
{$CLEO}
{$CLEO .cs}
{$USE CLEO+}
0000: nop

////-------------------------
:Restart
wait 0 

if
 $ONMISSION == 1
 then
  jump @Restart
end
////-----------------------------
 
 /////////////////////////////////////////////////////////////////////////////////////// MADE BY: ANDREW THIAGO
 
 
 /////0D4D: copy_string "yes" to 0@  ''Empty'' to ''television'' and such.

 
 

// 0@ = NPC CALLER
// 1@ = PHONE SOUND
// 2@ = TELEPHONE OBJ FROM NPC CALLER!
// 3@ = Bobcat
// 4@ = MARKER above BOBCAT 3@

// 5@ = PLAYER X
// 6@ = PLAYER Y
// 7@ = PLAYER Z

// 8@ = HOLDING OBJECT 
// 9@ = ID OF HOLDING OBJECT

// 10@ = BOBCAT X
// 11@ = BOBCAT Y
// 12@ = BOBCAT Z

// 13@ = distance_between_XY 4@ 5@ and_XY 10@ 11@  BOBCAT AND PLAYER
// 14@ = PLAYER'S TELEPHONE!!

Var $MaxObjectsToSteal_Value: int
///////////////
$MaxObjectsToSteal_Value = 12 ///// MAX OBJECTS TO STEAL TO DEFINE THE FINAL VALUE OF $StoredItens and the whole script 9 (MAX IS 12!)
////////////////-------------

0@ = -1  // 0@ = NPC CALLER
1@ = -1  // 1@ = PHONE SOUND
2@ = -1  // 2@ = TELEPHONE OBJ FROM NPC CALLER
3@ = -1  // 3@ = Bobcat  VEHICLE
4@ = -1  // 4@ = MARKER above BOBCAT 3@

Var 8@: object
Var 9@: int
Var 10@: int
Var $16V: object


14@ = -1 // 14@ = PLAYER'S TELEPHONE!!
$16V = -1 // Object handle when picking it up!
$16V = -1
8@ = -1 // Object handle when picking it up!
//////////---------------------

$PHONE_IS_OPEN = 0   // 2@ = TELEPHONE OBJ-
$CalledUnknownCaller = 0 // If player called unknown called when reached Bobcat Loc
$WL = -1 /// Player wanted level value
////////
Var $Total_ObjectsToSteal: int
//////
$Total_ObjectsToSteal = 0 //// It must have 6 slots filled with objects categories. Each category is a type of object to steal
$CurrentSlot = 0
$ItemAccepted = 0 
$StoredItens = 0 /// How many "borrowed" itens were accepted to be put in the trunk?
$BobCatTrunk = 6

$DisableBobCatMarker = 0

$Dropoff_Message1 = 0
$Dropoff_Message2 = 0

$IsLiftingNow = 0
Var $LastScannedObject: object
$LastScannedObject = -1

Var $ClonedRegister: object
$ClonedRegister = -1

Var $BurglaryPayout: int 
Var $StoredItens: int


Var $Boxville: car
Var $BoxvilleDriver: actor
////-------------
$Boxville = -1
$BoxvilleDriver = -1
$BurglaryPayout = 0

// ===================================================================
// --- FIX: ADD EXPLICIT STRING DECLARATIONS TO PREVENT MEMORY OVERLAPS ---
// ===================================================================

Var $ObjNam1: LongString
Var $ObjNam2: LongString
Var $ObjNam3: LongString
Var $ObjNam4: LongString
Var $ObjNam5: LongString
Var $ObjNam6: LongString
////////////////
Var $ObjNam7: LongString
Var $ObjNam8: LongString

/////////////////////////
Var $TempObjString: LongString
Var $PickedCategory: LongString

/////////////////////////
Var
 $StringSlot1: LongString
  $StringSlot2: LongString
   $StringSlot3: LongString
    $StringSlot4: LongString
     $StringSlot5: LongString
      $StringSlot6: LongString
       $StringSlot7: LongString
        $StringSlot8: LongString
                 
         $EletrString1: LongString
         $EletrString2: LongString
         $EletrString3: LongString
         $EletrString4: LongString
         $EletrString5: LongString
         $EletrString6: LongString
         $EletrString7: LongString
         $EletrString8: LongString
end







// ===================================================================

Var $ObjVal1: int
Var $ObjVal2: int
Var $ObjVal3: int
Var $ObjVal4: int
Var $ObjVal5: int
Var $ObjVal6: int
///////ADDITIONAL ROW FOR ITENS
Var $ObjVal7: int
Var $ObjVal8: int


////////////////////////////////////--------

Var $TempObjVar: int
///////////////////////
$ObjVal1 = 0
$ObjVal2 = 0
$ObjVal3 = 0
$ObjVal4 = 0
$ObjVal5 = 0
$ObjVal6 = 0
///////////////ADDITIONAL ROWS
$ObjVal7 = 0
$ObjVal8 = 0



////////////////////////////////////
$IsInBurglaryInterior = 0

Var $HouseStealer_Noise_F: Float
Var $HouseStealer_Noise_I: Int
Var $AccumulatedSoundValue: Int
Var $HouseStealer_Escape_Time: Int
/////////////////////////////

$HouseStealer_Noise_F = 0.0 ////  Current noise level returned by the game.
$HouseStealer_Noise_I = 0   ///// Integer value actually displayed as the Noise meter, from 0100.

$AccumulatedSoundValue = 0

$HouseStealer_Escape_Time = -1

Var $HouseStealer_EscapeTime_Crescent_Guard: int
$HouseStealer_EscapeTime_Crescent_Guard = -1

$HouseStealer_Escape_Active = 0

TIMERA = 0
$StopEscapeTimer = 0 /// Bool to deactivate TIMERA for Escape timer.

$NoiseReached100 = 0
$EscapeTimerIs0 = 0 

$HouseStealer_Escape_TimerStarted = 0
$ShowCountdownCounter = 1

//////////////////////////////
Var $InteriorPlayer_Is_In: int
Var $Last_InteriorPlayer_Was_In: int
Var $Last_CountDownTimer_Value: int
///////////////////////////////
$InteriorPlayer_Is_In = -1
$Last_InteriorPlayer_Was_In = -1
$Last_CountDownTimer_Value = 0

$MustEscape = 0

$Reset_BurglaryH_Vars = 0
/////////////////////////////////

/////FELONY VARIABLES

///////////////////////////////
Var $Felony_Quantity: int
Var $BobCatSpeed_Float: float
Var $BobCatSpeed: int
Var 23@: int
//////////////////////////
$Felony_Quantity = 0
TIMERB = 0
$Felony_Float_Quantity = 0.0
$BobCat_FelonyBar = 0

$BobCatSpeed_Float = 0

$PlayerIsWearingBurglaryBalackava = 0

$LSCP_MESSAGE1 = 0
$LSCP_MESSAGE2 = 0

$RandomPedInsideBurglaryHouse = -1
// $ResidentNPC_SawYou = 0

Var $Decres_Time_To_Set: int
$Decres_Time_To_Set = 0

//////////////////// DECLARE VARIABLES
Var
$CarFloat1 : float
$CarFloat2 : float
$CarFloat3 : float
$CarFloat4 : float
$CarFloat5 : float
$CarFloat6 : float
$CarFloat7 : float
$CarFloat8 : float
$CarFloat9 : float
$CarFloat10 : float
$CarFloat11 : float
$CarFloat12 : float
$CarFloat13 : float
end
//////////////////////
$CarFloat1 = -1 // Car X Coordinate
$CarFloat2 = -1 //Car Y Coordinate
$CarFloat3 = -1 // Car Z Coordinate
$CarFloat4 = -1 //Car Heading (Angle)
$CarFloat5 = -1 //Car Speed
$CarFloat6 = -1 //Nearest Road Path Angle
$CarFloat7 = -1 //Angle Difference (Absolute)
$CarFloat8 = -1
$CarFloat9 = -1
$CarFloat10 = -1
$CarFloat11 = -1
$CarFloat12 = -1
$CarFloat13 = -1

////////////////////////////////

Var $Television: int
Var $PlatesCups: int
Var $HIFI_MediaCenter: int
Var $VideoGame: int
Var $DVDPlayers: int
Var $NewsStands: int
Var $RugsAndMatt: int
Var $Microwave: int
Var $MagazinesNovelsBooks: int

Var $BobCat_Trunk1: int
Var $BobCat_Trunk2: int
Var $BobCat_Trunk3: int
Var $BobCat_Trunk4: int
Var $BobCat_Trunk5: int
Var $BobCat_Trunk6: int
//////////////ADDITIONAL ROWS 

Var $BobCat_Trunk7: int
Var $BobCat_Trunk8: int
Var $BobCat_Trunk9: int
Var $BobCat_Trunk10: int
Var $BobCat_Trunk11: int
Var $BobCat_Trunk12: int

//////////////////
Var $BobCat_Trunk1_Obj: object
Var $BobCat_Trunk2_Obj: object
Var $BobCat_Trunk3_Obj: object
Var $BobCat_Trunk4_Obj: object
Var $BobCat_Trunk5_Obj: object
Var $BobCat_Trunk6_Obj: object
/////////////////ADDITIONAL ROWS
Var $BobCat_Trunk7_Obj: object
Var $BobCat_Trunk8_Obj: object
Var $BobCat_Trunk9_Obj: object
Var $BobCat_Trunk10_Obj: object
Var $BobCat_Trunk11_Obj: object
Var $BobCat_Trunk12_Obj: object

// ===================================================================

//////////////////////
$Television = 0
$PlatesCups = 0
$HIFI_MediaCenter = 0
$VideoGame = 0
$DVDPlayers = 0
$RugsAndMatt = 0
$Microwave = 0
$MagazinesNovelsBooks = 0

///////////////////////////////////

$EletrString1 = "Television"
$EletrString2 = "Plate/Bowl"
$EletrString3 = "HI-FI"
$EletrString4 = "Game Console"
$EletrString5 = "DVD Player"
$EletrString6 = "Rug/Carpet"
$EletrString7 = "Microwave"
$EletrString8 = "Book/Mag"

///////////////////////////////////TEMPORARY NAMES OF STOLEN OBJECTS / SET VARS
//$TempObjString = " "

//$ObjNam1 = " "
//$ObjNam2 = " "
//$ObjNam3 = " "
//$ObjNam4 = " "
//$ObjNam5 = " "
//$ObjNam6 = " "
//$ObjNam7 = " "
//$ObjNam8 = " "

///////////////////////////////////
$StringSlot1 = "Empty"   //// String from slot
$EletrToSteal_Slot1 = -1  /// Variable containing ID of the object to steal
///--------------------------------------------------------
$StringSlot2 = "Empty"
$EletrToSteal_Slot2 = -1
///--------------------------------------------------------
$StringSlot3 = "Empty"
$EletrToSteal_Slot3 = -1
///--------------------------------------------------------
$StringSlot4 = "Empty"
$EletrToSteal_Slot4 = -1
///--------------------------------------------------------
$StringSlot5 = "Empty"
$EletrToSteal_Slot5 = -1
///--------------------------------------------------------
$StringSlot6 = "Empty"
$EletrToSteal_Slot6 = -1
///--------------------------------------------------------
$StringSlot7 = "Empty"
$EletrToSteal_Slot7 = -1
///--------------------------------------------------------
$StringSlot8 = "Empty"
$EletrToSteal_Slot8 = -1
///--------------------------------------------------------

$PickedCategory = "Empty"
$TempObjString = "Empty"
//////////////////////////////  TRUNK VARS to store trunk stolen objects
$BobCat_Trunk1 = -1
$BobCat_Trunk2 = -1
$BobCat_Trunk3 = -1
$BobCat_Trunk4 = -1
$BobCat_Trunk5 = -1
$BobCat_Trunk6 = -1
/////////////////////////
$BobCat_Trunk7 = -1
$BobCat_Trunk8 = -1
$BobCat_Trunk9 = -1
$BobCat_Trunk10 = -1
$BobCat_Trunk11 = -1
$BobCat_Trunk12 = -1

//////////////////////////////
$GivePLSprayCan1 = 1 /// Give player spray can

$RealDistofBobcat = 0.0


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

09E6: set_burglary_houses_accessible 0   //// CLOSE HOUSES TO STEAL!! FOR NOW THEY REMAIN CLOSED!
03CF: load_wav 23000 as 1
055E: set_player $PLAYER_CHAR max_health = 80



0247: request_model 28
0247: request_model 422 /// Bobcat 356.4834 -1787.8109 5.2842  ROT 91.9680

0570: $BurglaryPhoneRadarMarker = create_asset_radar_marker_with_icon 19 at 1807.7303 -1599.1021 13.5469  //// Burglary radar icon
018D: 1@ = create_sound 20600 at 1807.7303 -1599.1021 13.5469

/////////////////////////////////////////////////////////////
:Check_Start
wait 0
20@ = 1807.7303
21@ = -1599.1021
04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
0509: 19@ = distance_between_XY 5@ 6@ and_XY 20@ 21@


if
   00EC: actor $PLAYER_ACTOR sphere 0 near_point 1807.7303 -1599.1021 radius 8.4 8.4
then
 if
  timera > 3000
 then
  03D1: play_wav 1   
  timera = 0
else
   03D2: wav 1 ended
  end
end
///////////////////-----------------

/////////////////////---------------------------------------
if and
 00EC: actor $PLAYER_ACTOR sphere 0 near_point 1807.7303 -1599.1021 radius 1.0 1.0
 not $ONMISSION == 1
 then
    0AD1: show_formatted_text_highpriority "Press ~y~F to answer the payphone" time 3000
   $PayphoneTextTime = 0
end    

/////////////////////////////////////////////////////////////////////
if and
    0AB0: key_pressed 70
    00EC: actor $PLAYER_ACTOR sphere 0 near_point 1807.7303 -1599.1021 radius 1.0 1.0
    not $ONMISSION == 1
then
   $ONMISSION = 1  
   03BF: set_player $PLAYER_CHAR ignored_by_everyone 1
   Player.CanMove($PLAYER_CHAR) = False
   0164: disable_marker $BurglaryPhoneRadarMarker
   // 2. Fade out and wait for the screen to go black
   016A: fade 0 time 500
   wait 1000 
   // 3. Force load the scene in San Fierro
   03CB: set_rendering_origin_at -2434.9556 2345.8367 4.9688
   04E4: refresh_game_renderer_at -2434.9556 2345.8367 
   00A1: put_actor $PLAYER_ACTOR at -2425.3562 2349.9529 4.9688

   wait 1000 // Give the engine a full second to load the solid ground collision   
   // 4. Request the model and wait properly until it's loaded
   0247: request_model 28  /// NPC caller  //Drug black man
   if
    0248: not model 28 available
       wait 0
   009A: 0@ = create_actor_pedtype 4 model 28 at -2434.9556 2345.8367 5.9688
   0173: set_actor 0@ Z_angle_to 12.0752
   wait 200
   0249: release_model 28 // Free memory
   0107: 2@ = create_object #CELLPHONE at 0.0 0.0 0.0
   09A0: actor 0@ attach_object 2@ with_offset 0.0 0.0 0.0 on_bone 24 0 perform_animation "phone_talk" IFP_file "PED" time -1
   0812: AS_actor 0@ perform_animation "phone_talk" IFP "PED" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 0 time -1 
   wait 800
   015F: set_camera_position -2436.4573 2352.8967 5.9609 rotation 0.0 0.0 191.4486
   0160: set_camera_point_at -2434.9556 2345.8367 5.9688 switchstyle 2  //// Point at NPC caller
   016A: fade 1 time 1000
   /////--------------------
   if 
    0AB0: key_pressed 160
   then
     jump @RequestBobcat 
   end  
   /////--------------------
   wait 800 
   0AD1: show_formatted_text_highpriority "~w~Carl, you know, this city is growing dangerous everyday!" time 2300
   wait 2300
   0AD1: show_formatted_text_highpriority "~w~Sometimes i wonder what the hell the police chief is doing. I bet, anything, but fighting crime!" time 3200
   wait 3200
   0AD1: show_formatted_text_highpriority "~w~But that's exactly where we come in." time 2000
   wait 2000
   
   :RequestBobcat
   wait 0
   0247: request_model 422  /// Bobcat car
   if
    0248: not model 422 available
       wait 0
   ////CHANGE CAMERA TO THE BEACH
   016A: fade 0 time 1000
   wait 1000 
   03CB: set_rendering_origin_at 356.4834 -1787.8109 5.2842 
   04E4: refresh_game_renderer_at 356.4834 -1787.8109
   00A1: put_actor $PLAYER_ACTOR at 342.8317 -1812.2131 4.4339 
   wait 150
   00A5: 3@ = create_car 422 at 356.4834 -1787.8109 5.2842  /// Bobcat at the Marina Beach
   wait 150
   0175: set_car 3@ z_angle_to 91.9680
   02AC: set_car 3@ immunities BP 1 FP 1 EP 1 CP 1 MP 1  /// Invencible for now. 
   0A21: set_car 3@ not_affected_by_cheats 1
   wait 800  
   wait 1000
   015F: set_camera_position 346.6265 -1797.7469 4.8134 rotation 0.0 0.0 319.2664
   0160: set_camera_point_at 356.4834 -1787.8109 5.2842 switchstyle 2  
   016A: fade 1 time 800
   wait 800 
   0AD1: show_formatted_text_highpriority "~w~...Go to the pickup truck that is parked at the beach. As soon as you get there, give me a call. Will ya?" time 3000
   0165: set_marker 4@ color_to 0
   
   /////--------------------
   if 
    0AB0: key_pressed 160
   then
     jump @PutCJAtPayphoneBobCat
   end  
   /////--------------------
   
   wait 2500
   
   :PutCJAtPayphoneBobCat
   wait 0
   //////// PUT CJ BACK AT PAYPHONE
   jump @PutCJAtPayPhone
else  ///////// What happens while CJ is not near payphhone: 

 jump @Check_Start
end


////////////////////----------------------////////////////////////////////////
:PutCJAtPayPhone
wait 0
///////////////////------------------------
016A: fade 0 time 1000
   wait 1000  
   03CB: set_rendering_origin_at 1807.7303 -1599.1021 13.5469
   04E4: refresh_game_renderer_at 1807.7303 -1599.1021
   00A1: put_actor $PLAYER_ACTOR at 1807.7303 -1599.1021 13.5469
   0173: set_actor $PLAYER_ACTOR Z_angle_to 36.6603  
   015A: restore_camera
   0373: set_camera_directly_behind_player
   wait 700
   016A: fade 1 time 1200
   wait 1200  
   0682: detach_object 2@ 0.0 0.0 0.0 collision_detection 0
   wait 10
   0108: destroy_object 2@
   wait 10
   009B: destroy_actor 0@ //// DESTROY ACTOR CALLER
   0AD1: show_formatted_text_highpriority "~g~Get to the BobCat." time 3000
   lock_car_doors 3@ mode 4 //// LOCK BOBCAT DOORS
   0186: 4@ = create_marker_above_car 3@ /// BOBCAT
   set_blip_as_friendly 4@ type_to 1 ///////////////////////--------------
   Player.CanMove($PLAYER_CHAR) = true
   03BF: set_player $PLAYER_CHAR ignored_by_everyone 0
   0ACA: show_text_box "~w~When near the pickup truck, press ~g~M ~w~to call the unknown contact."
wait 2000

////////////////////////////
:GiveCall
wait 0 
gosub @MissionFailedCheck
///////////////////////////////////////////////////////////////
01C0: $WL = player $PLAYER_CHAR wanted_level
04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
0407: store_coords_to 11@ 12@ 13@ from_car 3@ with_offset 0.0 0.0 0.0
0509: 13@ = distance_between_XY 5@ 6@ and_XY 11@ 12@
//////-------------------------------------------------------


// FIRST, check if the player is pressing M and is allowed to make the call
if and
  0AB0: key_pressed 77 /// M 
  80DF: not actor $PLAYER_ACTOR driving 
  $CalledUnknownCaller == 0 
  $WL < 1 
then
    // THEN, check if they are close enough to the Bobcat
    if 
      13@ < 5.0
    then
        jump @OpenCellphone
    else
        // They pressed M, but are too far away
        0AD1: show_formatted_text_highpriority "~r~You need to be closer to the vehicle in order to make the call!" time 3100     
        wait 500 // Adding a short wait so the text doesn't spam rapidly if the player holds the M key for a fraction of a second
    end
end   

jump @GiveCall
//////////////////////////////////////////////////////////////////////////////


////////////////////----------------------//////////////////////////////////// ///////////////////////////////////////////////////>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                                            //////-------                       M I S S I O N    S T A R T     ////////////-----------<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
////////////////////----------------------////////////////////////////////////
:GetInBobCat
wait 0 
gosub @MissionFailedCheck
///////////////////------------------------
if and
 00DB: actor $PLAYER_ACTOR in_car 3@
 $DisableBobCatMarker == 0
then
 0164: disable_marker 4@
  0AD1: show_formatted_text_highpriority "~g~Find open houses around the city and gently 'borrow' the stuff." time 2000
  0729: AS_actor $PLAYER_ACTOR hold_cellphone 0
  wait 1500
 $DisableBobCatMarker = 1
end


if and
  $CalledUnknownCaller == 0 
  $WL < 1 
  $Message0 == 0  
then
    // THEN, check if they are close enough to the Bobcat
    if 
      13@ < 40.0
    then
      0ACA: show_text_box "~w~Stand close to the pickup truck. Then, press ~b~M to call the contact. Press ~g~SHIFT to select choice!"
      $Message0 = 1
      wait 4500 
   end   
end



///////////////////////////////////// DEACTIVATE BOBCAT IMMUNITIES
if 
  00DB: actor $PLAYER_ACTOR in_car 3@
then
 if 
  $PHONE_IS_OPEN == 0   // 2@ = TELEPHONE OBJ-
  $CalledUnknownCaller == 1  // If player called unknown called when reached Bobcat Loc
  not $ItemAccepted >= 6
then
  02AC: set_car 3@ immunities BP 0 FP 0 EP 0 CP 0 MP 0
  0164: disable_marker 4@
  09E6: set_burglary_houses_accessible 1
else
 0633: AS_actor $PLAYER_ACTOR exit_car
  end
end
//////////////////////////////////////////////////////




/////////////////////////////////////////////////SPRAY CAN//////////////////////////
0247: request_model #SPRAYCAN
038B: load_requested_models

:GiveSpraycan
wait 0
if
  $GivePLSprayCan1 == 0
then
  :SprayCanLoad
  wait 0
  if  
   0248: not model 41 available
   then 
    jump @SprayCanLoad
  else  
    if 
     $GivePLSprayCan1 == 0
     then 
      01B2: give_actor $PLAYER_ACTOR weapon 41 ammo 500
      end
   end   
end
//////////////////////////////////////////////////////////////////////////
04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
0407: store_coords_to $CP1 $CP2 $CP3 from_car 3@ with_offset 0.0 0.0 0.0
0509: $RealDistofBobcat = distance_between_XY 5@ 6@ and_XY $CP1 $CP2

/////////////////////////////////////////////////////// REPAIR VEHICLE
if and
  02D8: actor $PLAYER_ACTOR current_weapon == 41
  02E0: actor $PLAYER_ACTOR firing_weapon
 then
  if 
    $RealDistofBobcat < 1.7
   then
        0A30: repair_car 3@
        0ACA: show_text_box "~g~Vehicle has been repaired!"
        wait 800
        
    end
end
///////////////////////////////////////////////////////////


//0AD1: show_formatted_text_highpriority "~g~dist %d." time 300 $RealDistofBobcat



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//0AD1: show_formatted_text_highpriority "MODEL ID = %d" time 500 9@



//888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
///////////////////////////////////////////////////////>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>********------------------------
///////////////////////////////////////////////////////    P I C K  U P  O B J E C T S          ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
:CheckBurglaryObject
gosub @MissionFailedCheck
///////////////////------------------------

if
    Player.Defined($PLAYER_CHAR)
then
    04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0  
    
    // ===================================================================
    // --- 1. SCAN FOR NEARBY WORLD OBJECTS ---
    // ===================================================================
    // Only scan for new objects if we aren't already lifting one
    if
        $IsLiftingNow == 0
    then   
        if
         0AE3: 8@ = random_object_near_point 5@ 6@ 7@ in_radius 3.5 find_next 1   
        then
            if
              03CA: object 8@ exists
            then
                // Get model ID  
                0984: 9@ = object 8@ model
                
            
                // Check if this scanned object is already stored in the Bobcat trunk
                $IsStoredInTrunk = 0
                if or
                    8@ == $BobCat_Trunk1_Obj
                    8@ == $BobCat_Trunk2_Obj
                    8@ == $BobCat_Trunk3_Obj
                    8@ == $BobCat_Trunk4_Obj
                    8@ == $BobCat_Trunk5_Obj
                    8@ == $BobCat_Trunk6_Obj
                then
                    $IsStoredInTrunk = 1
                  //  print_now 'CPSO' time 2300 flag 1
                end
                  if or
                   8@ == $BobCat_Trunk7_Obj
                   8@ == $BobCat_Trunk8_Obj
                   8@ == $BobCat_Trunk9_Obj
                   8@ == $BobCat_Trunk10_Obj
                   8@ == $BobCat_Trunk11_Obj
                   8@ == $BobCat_Trunk12_Obj
                 then
                   $IsStoredInTrunk = 1
                  // print_now 'CPSO' time 2300 flag 1
                end
                
            //    $PickedCategory = "Invalid"
                0D4D: copy_string "Invalid" to $PickedCategory
                //$PickedCategory = "Invalid"
                0984: 9@ = object 8@ model
                gosub @IdentifyStolenObject
            
                // Only make the item liftable if it's a valid burglary item AND not already in the trunk
        
                if and
                    not $IsStoredInTrunk == 1
                   // not $PickedCategory == "Invalid"
                    //not $PickedCategory == "Invalid"
                    not 9@ == 1212
                 then      
                   08E9: set_object 8@ liftable 1 // Safe item: player can pick it up     
                 else          
                    08E9: set_object 8@ liftable 0 // Locked item
                    end
                 end
              end 
           end   
        end                       
 
                  
    if 
      0737: actor $PLAYER_ACTOR lifting_object 8@
      then
         $16V = 8@
   end

       if and
         0737: actor $PLAYER_ACTOR lifting_object $16V
         $16V > -1
         then
             $IsLiftingNow = 1    
             0984: 9@ = object $16V model                          
             //0AD1: show_formatted_text_highpriority "Holding: %d Real ID: %d" time 800 $16V 9@
        else
              $16V = -1
              $IsLiftingNow = 0
            
               //0AD1: show_formatted_text_highpriority "Dropped Object" time 800
            // 0AD1: show_formatted_text_highpriority "Lifting?: %d Stored itens: %d" time 500 $16V $StoredItens
      end  
  
  /////////////////////////
    // Control immunity via $IsLiftingNow, because 8@ changes too fast
    if
        $IsLiftingNow == 1
    then
        02AB: set_actor $PLAYER_ACTOR immunities BP 0 FP 0 EP 0 CP 1 MP 0
    else
        02AB: set_actor $PLAYER_ACTOR immunities BP 0 FP 0 EP 0 CP 0 MP 0
  end


//888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
//////////////////////////////// Show objects to steal if i already called unknown contact

if and    
  0AB0: key_pressed 117 // F5
  $CalledUnknownCaller == 1    
 then
   // Display Slots 1, 2, and 3
    0AD1: show_formatted_text_highpriority "Steal: 1: %s (x%d) ~n~2: %s (x%d) ~n~3: %s (x%d)" time 2000 $ObjNam1 $ObjVal1 $ObjNam2 $ObjVal2 $ObjNam3 $ObjVal3
    wait 2000
end

///////////////////////////////////////////////////
if and    
  0AB0: key_pressed 118 // F6
  $CalledUnknownCaller == 1    
 then
    // Display Slots 4, 5, and 6
    0AD1: show_formatted_text_highpriority "4: %s (x%d) ~n~5: %s (x%d) ~n~6: %s (x%d)" time 2000 $ObjNam4 $ObjVal4 $ObjNam5 $ObjVal5 $ObjNam6 $ObjVal6
    wait 2000
end    

///////////////////////////////////////    
if and    
  0AB0: key_pressed 119 // F7
  $CalledUnknownCaller == 1    
 then    
          // Display Slots 7, 8 and 9 
    0AD1: show_formatted_text_highpriority "7: %s (x%d) ~n~8: %s (x%d)" time 1500 $ObjNam7 $ObjVal7 $ObjNam8 $ObjVal8 
    wait 900
end    

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////









//////////////////////////////// Show objects to steal if i already called unknown contact
if and    
  0AB0: key_pressed 9 // TAB
  $CalledUnknownCaller == 1    
 then
    gosub @WhichItensToSteal_TextBox
end       
///////////////////////////////


///////////////////////////////////////PRESS G IN THE BACK OF THE BOBCAT: OPEN MENU TO PUT STOLEN OBJECTS

04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
0407: store_coords_to 11@ 12@ 13@ from_car 3@ with_offset 0.0 -2.5 0.0
/////////////////////////--------------------------------
0509: 15@ = distance_between_XY 5@ 6@ and_XY 11@ 12@

// 2. Draw the sphere only if CJ is within 15.0 meters of the Bobcat trunk
if
  15@ < 8.0
then
  03A1: show_sphere_at 11@ 12@ 13@ radius 1.2
end

//////--------------

// 3. OPEN THE MENU
if and
  00EC: actor $PLAYER_ACTOR sphere 0 near_point 11@ 12@ radius 2.0 2.0
  80DF: not actor $PLAYER_ACTOR driving.
 then
   if   
    0AB0: key_pressed 71 // G key  
    then
     wait 100
    jump @BobCatTrunkMENU
  end
end
//////////////////////////////////////////////////////////////////////////////////////////////



//////////////// DRESS / UNDRESS MASK
if 
    0AB0: key_pressed 66  // Key 'B'
then
    // Wait until key is released so it does not rapidly loop
    while 0AB0: key_pressed 66
        wait 0
    end

    // Load animation library for hand gesture
    04ED: load_animation "GHANDS"
   // while 04EE: not animation "GHANDS" loaded
     //   wait 0
  //  end

    // Prevent issues if player is in a vehicle or performing actions
    if //and
        //not is_char_in_any_car $PLAYER_ACTOR
        not is_char_dead $PLAYER_ACTOR
    then
        // ==========================================
        // 1. WEAR MASK
        // ==========================================
        if 
            $PlayerIsWearingBurglaryBalackava == 0
        then
            // Play hand gesture to head
            0812: AS_actor $PLAYER_ACTOR perform_animation "gsign5LH" IFP "GHANDS" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time 800
            wait 200 // Brief delay so the mask appears as the hand touches the head

            give_player_clothes_outside_shop $PLAYER_CHAR clothes_texture "BALACLAVA" model "BALACLAVA" body_part BodyPart.SpecialCostume
            build_player_model $PLAYER_CHAR 
            0AD1: show_formatted_text_highpriority "~W~Wearing the Balaclava." time 1500
            $PlayerIsWearingBurglaryBalackava = 1
          //  wait 400

        // ==========================================
        // 2. REMOVE MASK
        // ==========================================
        else
            // Play hand gesture to head
            0812: AS_actor $PLAYER_ACTOR perform_animation "gsign5LH" IFP "GHANDS" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time 800
            wait 200 // Brief delay so the mask disappears as the hand reaches up

            // Remove Special Costume (BodyPart 17 / SpecialCostume)
            give_player_clothes $PLAYER_CHAR textureCRC 0 modelCRC 0 bodypart 17
            build_player_model $PLAYER_CHAR
            0AD1: show_formatted_text_highpriority "~W~You took the Balaclava off." time 1500
            $PlayerIsWearingBurglaryBalackava = 0
            //wait 400
        end
    end

    // Release animation library from memory
    04EF: remove_animation "GHANDS"
end
///////////////////////////////////////////
    



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// BURGLARY NOISE & ESCAPE SYSTEM
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////------------------------------------------------------------------------------------------------------------------------------------------------------
////////////////////////////////////////////////////////////         B U R G L A R Y   S E C T I O N   ---

////////////////// Ensure there is a master wait at the beginning or end of your main loop iteration
wait 0 

if
 0867: not unknown_in_burglary_interior 0 &&
 010F: not player $PLAYER_CHAR wanted_level > 0 &&
 not $LSCP_MESSAGE1 == 1 &&
 $LSCP_MESSAGE2 == 1
then
 print_now 'LSCP' time 4000 flag 1 //"~r~Lose the cops if you still want to burglar the houses!" 
 09E6: set_burglary_houses_accessible 0
 clear_this_print 'LSCP'
 $LSCP_MESSAGE1 = 1
else
 if
  0867: not unknown_in_burglary_interior 0 &&
  010F: player $PLAYER_CHAR wanted_level > 0 
  not $LSCP_MESSAGE2 == 1
  $LSCP_MESSAGE1 == 1
 then
   print_now 'CPH' time 4000 flag 1  //"~g~Now you can go back to the job. But avoid filling the ~y~Felony~g~bar too much!" 
   09E6: set_burglary_houses_accessible 1
   $LSCP_MESSAGE2 = 1
   $LSCP_MESSAGE1 = 0
  end
end


///////////////////////////////////////////RESET VALUES
if
  0867: unknown_in_burglary_interior 0
then
  $IsInBurglaryInterior = 1
else
 $IsInBurglaryInterior = 0
    clear_onscreen_counter $HouseStealer_Noise_I
    clear_onscreen_counter $HouseStealer_Escape_Time
    $StopEscapeTimer = 0
    $HouseStealer_Escape_Time = 0
    $HouseStealer_EscapeTime_Crescent_Guard = 0
    $HouseStealer_Noise_I = 0
    $HouseStealer_Noise_F = 0.0    
    TIMERA = 0    
    $HouseStealer_Escape_Active = 0 
    $HouseStealer_Escape_TimerStarted = 0
    $MustEscape = 0
    $Reset_BurglaryH_Vars = 0
    // $ResidentNPC_SawYou = 0
    $RandomPedInsideBurglaryHouse = -1
    09E6: set_burglary_houses_accessible 1
end  


///////////////////////////////////////////////// RESET HOUSE VARIABLES WHEN INSIDE
 if and 
 0867: unknown_in_burglary_interior 0 && 
 $Reset_BurglaryH_Vars == 0
 then
   clear_onscreen_counter $HouseStealer_Escape_Time
   TIMERA = 0    
    $HouseStealer_Escape_Active = 0 
    // Reset escape timer and noise variables for the new house
    $HouseStealer_Escape_Time = 0
    $HouseStealer_Escape_TimerStarted = 0
    $HouseStealer_EscapeTime_Crescent_Guard = 0
    $HouseStealer_Noise_I = 0
    $HouseStealer_Noise_F = 0.0
    $StopEscapeTimer = 0
    $MustEscape = 0
    $AccumulatedSoundValue = 0
    $Reset_BurglaryH_Vars = 1
    // $ResidentNPC_SawYou = 1
end  

//////////////////////////////////////////////////////////////////////

//////////////////////////////// CLOSE ACCESS OR OPEN ACCESS TO BURGLARY HOUSES WHEN COUNTDOWN IS ON.
  
if  
  0867: unknown_in_burglary_interior 0    
 then
  if or  
   $MustEscape == 1 
   $HouseStealer_Escape_Active == 1
 then
   09E6: set_burglary_houses_accessible 0
else
  if  
     0867: not unknown_in_burglary_interior 0   
   then
    if or   
     $MustEscape == 1  
     $HouseStealer_Escape_Active == 1
  then
    $RandomPedInsideBurglaryHouse = -1
    wait 1100
    09E6: set_burglary_houses_accessible 1
        end
     end
  end  
end  
/////////////////////////////





///////////////////////////////////// NOISE LEVEL CALCULATION WHILE INSIDE A BURGLARY INTERIOR
 if and
    //$IsInBurglaryInterior = 1
    0867: unknown_in_burglary_interior 0
    not $HouseStealer_Escape_Active == 1 
    not $MustEscape == 1
then
    clear_onscreen_counter $HouseStealer_Escape_Time
    shut_char_up $PLAYER_ACTOR muted 1
    display_nth_onscreen_counter_with_string $HouseStealer_Noise_I type 1 line 2 GXT 'HS1' // Noise  ///////// DISPLAY NOISE METER
   // 5@, 6@, 7@ = get_char_coordinates $PLAYER_ACTOR
    04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
    get_sound_level_at_coords -1 noise_level_at 5@ 6@ 7@ store_to $HouseStealer_Noise_F
    $HouseStealer_Noise_F *= 1.6 // 1.6
  end 
   
///////////////////  EQUILIBRATE THE NOISE LEVEL IF I'M NOT MAKING ANY MORE NOISE  
  if and
   $HouseStealer_Noise_F > 20.0 //20
  // $IsInBurglaryInterior = 1
   0867: unknown_in_burglary_interior 0
  then 
     $HouseStealer_Noise_F -= 20.0 //20
     add_float_var_to_float_lvar $AccumulatedSoundValue += $HouseStealer_Noise_F
  end  
  
    $AccumulatedSoundValue *= 0.99 //0.99   //-- 0,97 makes noise decrease slighty faster
    cset_var_int_to_lvar_float $HouseStealer_Noise_I = float $AccumulatedSoundValue
    
  if
   $HouseStealer_Noise_I >= 100
then
    $HouseStealer_Noise_I = 100
end  
///////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//0AD1: show_formatted_text_highpriority "NPC ID = %d" time 500 $RandomPedInsideBurglaryHouse 


/////////////////////////////////////// IF NOISE IS 100%
if 
 0867: unknown_in_burglary_interior 0 
 then
if 
  $HouseStealer_Noise_I >= 100 
  then
      $MustEscape = 1       
 end
/////////////////////////////////////// 



//////////////////////////////////////////////////////////
// GET PLAYER COORDS CORRECTLY (5@ = X, 6@ = Y, 7@ = Z)
04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0

if
  0867: unknown_in_burglary_interior 0
then
    if and
        $HouseStealer_Noise_I < 100 &&
        $MustEscape == 0
    then
        // 1. Initialize ped search loop (find_next = 0 for first ped)
        0AE1: $RandomPedInsideBurglaryHouse = random_char_near_point 5@ 6@ 7@ in_radius 15.0 find_next 0 pass_deads 1
        if
         $RandomPedInsideBurglaryHouse > -1
          then
            // Check if ped is valid and not the player
            if and
                does_char_exist $RandomPedInsideBurglaryHouse &&
                not is_char_dead $RandomPedInsideBurglaryHouse
            then
                // Checks if ped is NOT playing standard sleeping/lying animations
                if and
                    not is_char_playing_anim $RandomPedInsideBurglaryHouse "BED_Loop_L"
                    not is_char_playing_anim $RandomPedInsideBurglaryHouse "BED_Loop_R"
                    not is_char_playing_anim $RandomPedInsideBurglaryHouse "BED_In_L"
                    not is_char_playing_anim $RandomPedInsideBurglaryHouse "BED_In_R"
                    not is_char_playing_anim $RandomPedInsideBurglaryHouse "crckidle2"
                    not is_char_playing_anim $RandomPedInsideBurglaryHouse "crckidle4"
                then
                    // If they are awake and standing/moving around, trigger alarm
                    $HouseStealer_Noise_I = 100
                    $MustEscape = 1
                    //$RandomPedInsideBurglaryHouse = -1
                    0AD1: show_formatted_text_highpriority "~r~RESIDENT WOKE UP!" time 2000
                else
                
            
                // Check if ped was hurt or is responding to events
                if or
                    051A: char $RandomPedInsideBurglaryHouse damaged_by_actor $PLAYER_ACTOR
                    is_char_responding_to_event $RandomPedInsideBurglaryHouse ped_event == 9   // EVENT_ACQUAINTANCE_PED_HATE
                    is_char_responding_to_event $RandomPedInsideBurglaryHouse ped_event == 15  // EVENT_ACQUAINTANCE_PED_DISLIKE
                    is_char_responding_to_event $RandomPedInsideBurglaryHouse ped_event == 27  // EVENT_DAMAGE
                    is_char_responding_to_event $RandomPedInsideBurglaryHouse ped_event == 31  // EVENT_GUN_AIMED_AT
                    is_char_responding_to_event $RandomPedInsideBurglaryHouse ped_event == 36  // EVENT_SEEN_PANIC_PED
                    is_char_responding_to_event $RandomPedInsideBurglaryHouse ped_event == 50  // EVENT_SEEN_COP / Low anger
                 then
                    //$HouseStealer_Noise_I = 100
                    $MustEscape = 1
                    //$RandomPedInsideBurglaryHouse = -1
                    0AD1: show_formatted_text_highpriority "~r~RESIDENT SAW/HEARD YOU!" time 2000
                else // Stop iterating through peds, alarm is triggered           
                
                 if or   
                    is_char_responding_to_event $RandomPedInsideBurglaryHouse ped_event == 51  // High hate player
                    is_char_responding_to_event $RandomPedInsideBurglaryHouse ped_event == 61  // EVENT_SOUND_LOUD
                    is_char_responding_to_event $RandomPedInsideBurglaryHouse ped_event == 75 //Danger
                    is_char_responding_to_event $RandomPedInsideBurglaryHouse ped_event == 49 // EVENT_SHOT_FIRED_WHIZZED_BY
                    is_char_responding_to_event $RandomPedInsideBurglaryHouse ped_event == 4 //EVENT_PLAYER_COLLISION_WITH_PED                    
                    //is_char_responding_to_event $RandomPedInsideBurglaryHouse ped_event == 62  // EVENT_SOUND_QUIET
                then
                    //$HouseStealer_Noise_I = 100
                    $MustEscape = 1
                    //$RandomPedInsideBurglaryHouse = -1
                    09E6: set_burglary_houses_accessible 0
                    0AD1: show_formatted_text_highpriority "~r~RESIDENT SAW/HEARD YOU!" time 2000
                    //break // Stop iterating through peds, alarm is triggered
               end
            // Find next ped in the interior (find_next = 1)
            //$RandomPedInsideBurglaryHouse = -1
            $RandomPedInsideBurglaryHouse = -1
            0AE1: $RandomPedInsideBurglaryHouse = random_char_near_point 5@ 6@ 7@ in_radius 35.0 find_next 1 pass_deads 1  
                end 
             end 
          end                                   
       end
   end
end
///////////////////////////////////--------------------------------------------------------------------------------------------------------------

////////////////////////////////////  WEARING BALACLAVA
if  
  0867: unknown_in_burglary_interior 0 
 then
 if 
  $HouseStealer_Escape_Active == 0 &&
  $MustEscape == 1 &&
  not $PlayerIsWearingBurglaryBalackava == 0 
 then
    $Decres_Time_To_Set = 20
    wait 20
   end
end 
///////////////////////////

///////////////////////////  NOT WEARING BALACLAVA
if  
  0867: unknown_in_burglary_interior 0 
 then
if  
  $HouseStealer_Escape_Active == 0 &&
  $MustEscape == 1 &&
  not $PlayerIsWearingBurglaryBalackava == 1 
 then
   $Decres_Time_To_Set = 10
   wait 20
   end
end 
///////////////////////////


////////////////444444444444444444444444444444444444444444444444444444444444444444444444444444444444
                                                        /////////   TIMER COUNTDOWN
////////////////4444444444444444444444444444444444444444444444444444444444444444444444444444444444444
///////////////////////////////////////////////// IF NOISE REACHES 100%. SHOW MESSAGE ABOUT COPS COMING. THE NEXT SECTION ACTIVATES TIMER --------------------------


if 
 0867: unknown_in_burglary_interior 0 
 then
   if and
    $MustEscape == 1 &&
    $HouseStealer_Escape_Active == 0
    then
      //$HouseStealer_Escape_Active = 1   //// Activation variable to turn on COPS countdown counter 
      clear_onscreen_counter $HouseStealer_Noise_I
     //display_nth_onscreen_counter_with_string $HouseStealer_Escape_Time type 0 line 2 GXT 'HS_COPS' 
      $HouseStealer_EscapeTime_Crescent_Guard = 0 /// Var to work with Escape time Var, to make sure counter reached 0 after countdown and not a bug.
      $HouseStealer_Escape_Time = $Decres_Time_To_Set
      $MustEscape = 1     
      $HouseStealer_Escape_Active = 1   
      TIMERA = 0 
      0AD1: show_formatted_text_highpriority "~r~You have %d seconds to leave the house!" time 1800 $Decres_Time_To_Set
   end
end
/////////////////----------------/////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////  COUNTER WILL GO DOWN FROM 10. TIMER IS ON.   --------------------------/// NOT USING BALACLAVA
// COUNTER WILL GO DOWN FROM 10. TIMER IS ON.
if 
  0867: unknown_in_burglary_interior 0 
then
    if and
        $StopEscapeTimer == 0 &&
        $MustEscape == 1 && 
        $HouseStealer_Escape_Active == 1  && /// - Adding it seemed to make things work now.     
        //$HouseStealer_EscapeTime_Crescent_Guard < $Decres_Time_To_Set  
        not $HouseStealer_Escape_TimerStarted == 1    
    then
        //clear_onscreen_counter $HouseStealer_Noise_I
        
        display_nth_onscreen_counter_with_string $HouseStealer_Escape_Time type 0 line 2 GXT 'HS_COPS'
       
        // Timer countdown
        if 
         TIMERA >= 1000
        then
          $HouseStealer_Escape_Time -= 1
          $HouseStealer_EscapeTime_Crescent_Guard += 1
          TIMERA = 0
      end
   end
end
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if 
  0867: unknown_in_burglary_interior 0 
 then
  if and
    $MustEscape == 1 && 
     $HouseStealer_Escape_Active == 1 &&  
     $HouseStealer_Escape_TimerStarted == 0 &&
     $HouseStealer_EscapeTime_Crescent_Guard == $Decres_Time_To_Set && 
   then
     $StopEscapeTimer = 1
    $HouseStealer_Escape_TimerStarted = 1
      end
   end
end  
 
 

///////////////////////////// ///////////////////////////// ///////////////////////////// ///////////////////////////// 

/////////////////////////       CALL COPS IF STILL INSIDE BURGLARY HOUSE --- 
if 
  0867: unknown_in_burglary_interior 0 
 then
  if and
    $MustEscape == 1 &&
    $HouseStealer_Escape_Active == 1 &&
    $HouseStealer_Escape_TimerStarted == 1 && 
    $StopEscapeTimer == 1   
then    
    TIMERA = 0
    $HouseStealer_Escape_Time = 0  
    $StopEscapeTimer = 1
    $HouseStealer_EscapeTime_Crescent_Guard = 0
    $HouseStealer_Noise_I = 0
    $Decres_Time_To_Set = 0
    clear_onscreen_counter $HouseStealer_Escape_Time
    0AD1: show_formatted_text_highpriority "~r~The cops are coming!!!" time 4000
    wait 1500
    010D: set_player $PLAYER_CHAR wanted_level_to 4     
    09E6: set_burglary_houses_accessible 0  
   end
end     
//////////////////////////////////////////////////////////////////    

 
////////////////////////    IF MANAGED TO LEAVE HOUSE ON TIME!

if and 
 0867: not unknown_in_burglary_interior 0 && 
 $IsInBurglaryInterior == 0 &&
 $HouseStealer_Escape_TimerStarted == 0 &&
 $HouseStealer_Escape_Active == 1
 then 
if and 
  $HouseStealer_EscapeTime_Crescent_Guard < 10 && 
  $HouseStealer_Escape_Time > 0 &&
then     
    TIMERA = 0    
    $HouseStealer_Escape_Active = 0 
    // Reset escape timer and noise variables for the new house
    $HouseStealer_Escape_Time = -1
    $HouseStealer_Escape_TimerStarted = 0
    $HouseStealer_EscapeTime_Crescent_Guard = 0
    $HouseStealer_Noise_I = 0
    $HouseStealer_Noise_F = 0.0
    $StopEscapeTimer = 0
    $MustEscape = 0
    $AccumulatedSoundValue = 0
    $RandomPedInsideBurglaryHouse = -1
    clear_onscreen_counter $HouseStealer_Escape_Time
    09E6: set_burglary_houses_accessible 1
  end
 end  

////////////////////////////////////////////////////////////////////////////////////////////// 
///////////////////////////////////////////////-------------------------------------------------------------------------------------------------------------------------------------------------999999999999999999999999999999999999999999999999999999999    
    




   
   
   
   
   
   
   
   
   
   
   
   
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////------------------------///////////////////////////////////////////////------------------------
//                                                       CAR ****** F E L O N Y  B A R   *****  S E C T I O N 
/////////////////////////////////////////////////////////////////////////////////////////////////////////------------------------///////////////////////////////////////////////------------------------
    
04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
0407: store_coords_to 11@ 12@ 13@ from_car 3@ with_offset 0.0 -2.5 0.0
0294: set_car 3@ sprayable 0
0A14: disable_respray_garages 1


01C0: $PlayerWantedL = player $PLAYER_CHAR wanted_level


//////////////////////////// PREVENT FELONY BAR FROM EXCEEDING 100
if 
 $Felony_Quantity >= 100
then
    $Felony_Quantity = 100
end
////////////////////////


//////////////////////// CALL COPS IF FELONY IS HIGH

if 
 $Felony_Quantity >= 100
then
    //010F: player $PLAYER_CHAR wanted_level > 3   
    010E: set_player $PLAYER_CHAR minimum_wanted_level_to 3
    09E6: set_burglary_houses_accessible 0  
end

////////////////////////  ///////////////////////////////--------------  



/////////////////////////////// --> FIX 1 & 2: GET SPEED PROPERLY AND ASSIGN IT <--
if and
  00DB: actor $PLAYER_ACTOR in_car 3@ &&
  $PlayerWantedL == 0 
  //80DF: actor $PLAYER_ACTOR driving  
then
    0E65: get_car_collision_intensity 3@ store_to 18@
    
    02E3: 22@ = car 3@ speed             // 22@ now holds the FLOAT speed
    008B: 23@ = float 22@ to_integer     // Converts 22@ float into INT and stores in 23@    
    $BobCatSpeed = 23@                   // Assign the integer to your UI counter variable    
    display_nth_onscreen_counter_with_string $Felony_Quantity type 1 line 1 GXT 'FLB'
else
    $BobCatSpeed = 0
    22@ = 0.0
    18@ = 0.0
    clear_onscreen_counter $Felony_Quantity
end
/////////////////////////////////

////////////////////////// BOB CAT COLLISION INTENSITY
if and  
    $BobCatSpeed > 4.0 && /// Speed
    18@ > 3.0 && /// IMPACT FORCE
    TIMERB > 100
then
    $Felony_Quantity += 4
    TIMERB = 0 // 
end
/////////-------------

if and  
    $BobCatSpeed > 6.5 &&
    18@ > 3.0 &&
    TIMERB > 100
then
    $Felony_Quantity += 10
    TIMERB = 0 // 
end

/////////////////////////----------

if and  
    $BobCatSpeed > 13.0 &&
    18@ > 3.0 &&
    TIMERB > 100
then
    $Felony_Quantity += 15
    TIMERB = 0 // 
end
//////////////////////////////////////////////////


///////////////////////////////////////////////////////////////// SUBTRACT FELONY BAR VALUE WHEN IN VEHICLE 
if and
    00DB: actor $PLAYER_ACTOR in_car 3@
    $Felony_Quantity > 50 
then
    if TIMERB > 5000
    then
        $Felony_Quantity -= 4
        TIMERB = 0
    end       
end
///--------------
if and
    00DB: actor $PLAYER_ACTOR in_car 3@
    $Felony_Quantity > 87
then
    if TIMERB > 3500
    then
        $Felony_Quantity -= 10
        TIMERB = 0
    end       
end
/////////////////////////////////////

wait 0
///////////////////////////////////////////////////////////////// FIND POLICE OFFICERS NEAR PLAYER WHEN HOLDING AN OBJECT
04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
0407: store_coords_to 11@ 12@ 13@ from_car 3@ with_offset 0.0 0.0 0.0
 

if
  $PlayerWantedL == 0
  //0AE1: $PolicePedAroundPlayer = random_char_near_point 5@ 6@ 7@ in_radius 35.0 find_next 0 pass_deads 1
  
 then 
    0EA5: get_closest_cop_near_char $PLAYER_ACTOR radius 35.0 alive 1 in_car 0 on_foot 1 seen_in_front 0 store_to $PolicePedAroundPlayer
   if 
     //056D: actor $PolicePedAroundBobCat defined 
     $PolicePedAroundPlayer > -1
    //then
       // 089F: get_actor $PolicePedAroundPlayer pedtype_to 24@ 
        //0665: get_actor $PolicePedAroundPlayer model_to 24@
      // if or
            //24@ == 6 
          //  24@ == 280
          //  24@ == 281
          //  24@ == 282
          //  24@ == 283
          //  24@ == 284
          //  24@ == 285
         //   24@ == 286
          //  24@ == 287
         //   24@ == 288
         //   24@ == 523
          then
            if and
                0737: actor $PLAYER_ACTOR lifting_object $16V &&
                $PlayerIsWearingBurglaryBalackava == 1 &&
                80DF: not actor $PLAYER_ACTOR driving 
            then
                print_now 'POLH3' time 2000 flag 1 //~r~Police saw you wearing the Balaclava while carrying an stolen object. Avoid doing that!
                010D: set_player $PLAYER_CHAR wanted_level_to 3    
            else    
            
            
            
            
            if and
                $Total_ObjectsToSteal > 2
                0737: actor $PLAYER_ACTOR lifting_object $16V &&
                not $PlayerIsWearingBurglaryBalackava == 1 &&
                80DF: not actor $PLAYER_ACTOR driving 
            then
                print_now 'POLH4' time 2000 flag 1 //~r~Police saw you carrying a stolen object!
                010D: set_player $PLAYER_CHAR wanted_level_to 1    
            else    
            
            if and
                $PlayerIsWearingBurglaryBalackava == 1 &&
                80DF: not actor $PLAYER_ACTOR driving
            then
                $Felony_Quantity += 1
                print_now 'POLH2' time 3000 flag 1 //~r~Police saw you wearing the Balaclava. Do not use it while in public!
                wait 200
            else    
            
            if and
               $PlayerIsWearingBurglaryBalackava == 1 &&
               80DF: actor $PLAYER_ACTOR driving
             then
              $Felony_Quantity += 1
              print_now 'POLH0' time 3000 flag 1   //~r~A street cop saw you wearing the Balaclava. Do not use it while in public!
              wait 200
          end        
             //$PolicePedAroundPlayer = -1
          //  0AE1: $PolicePedAroundPlayer = random_char_near_point 5@ 6@ 7@ in_radius 35.0 find_next 1 pass_deads 1 
            0EA5: get_closest_cop_near_char $PLAYER_ACTOR radius 35.0 alive 1 in_car 0 on_foot 1 seen_in_front 0 store_to $PolicePedAroundPlayer
         end   
      end      
   end
end

:PoliceCarSearch
wait 0
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if //and
    //00DB: actor $PLAYER_ACTOR in_car 3@
    $PlayerWantedL == 0
then

    02E3: $BobCatSpeed = car 3@ speed

    // Search nearby vehicles
    0407: store_coords_to 11@ 12@ 13@ from_car 3@ with_offset 0.0 0.0 0.0

   // if
     // 0AE2: $PoliceCarAroundBobCat = random_vehicle_near_point 11@ 12@ 13@ in_radius 50.0 find_next 0 pass_wrecked 1   
     
    //then
      //  0441: 25@ = car $PoliceCarAroundBobCat model

      //  if or
          //  25@ == 596
          //  25@ == 597
          //  25@ == 598
          //  25@ == 599
          //  25@ == 600
          //  25@ == 601
       // then
        0EA5: get_closest_cop_near_char $PLAYER_ACTOR radius 45.0 alive 1 in_car 1 on_foot 0 seen_in_front 0 store_to $PoliceCarAroundBobCat
        
       if        
          $PoliceCarAroundBobCat > -1
         then 
            if or
                $BobCatSpeed >= 20.0   /// IF SPEEDING
                23@ >= 20.0 
                22@ >= 20.0
            then
                $Felony_Quantity += 5
                print_now 'POLH' time 2000 flag 1
             else              
                
             if and
                 $PlayerIsWearingBurglaryBalackava == 1 && /// IF WEARING MASK WHILE DRIVING
                 80DF: actor $PLAYER_ACTOR driving
             then
                print_now 'POLH2' time 2000 flag 1
                $Felony_Quantity += 1               
            else
            
            if and  
                $PlayerIsWearingBurglaryBalackava == 0 &&  ///// NOT WEARING BALACLAVA WHILE CARRYING STOLEN OBJECT6             
                0737: actor $PLAYER_ACTOR lifting_object $16V  
            then
                print_now 'POLH4' time 2000 flag 1
                010D: set_player $PLAYER_CHAR wanted_level_to 2           
            else
                                                           
           if and
                $PlayerIsWearingBurglaryBalackava == 1 && ///// WEARING BALACLAVA WHILE CARRYING STOLEN OBJECT
                0737: actor $PLAYER_ACTOR lifting_object $16V 
            
            then
                print_now 'POLH3' time 2000 flag 1
                010D: set_player $PLAYER_CHAR wanted_level_to 3           
            end
             0EA5: get_closest_cop_near_char $PLAYER_ACTOR radius 35.0 alive 1 in_car 1 on_foot 0 seen_in_front 0 store_to $PoliceCarAroundBobCat  
                       
      //  if or   
         //   25@ == 433
         //   25@ == 427
          //  25@ == 490
          //  25@ == 528 
      //  then
           // if or
            //    $BobCatSpeed >= 20.0 
            //    23@ >= 20.0 
           //     22@ >= 20.0
           // then
            //    $Felony_Quantity += 5
            //    print_now 'POLH' time 2000 flag 1               
        //  end 
                
         //    if and
            //   $PlayerIsWearingBurglaryBalackava == 1 &&
           //    80DF: actor $PLAYER_ACTOR driving
           //  then
            //   print_now 'POLH2' time 2000 flag 1
            //   $Felony_Quantity += 2
            //  end          
           
         //  if and
            //    0737: actor $PLAYER_ACTOR lifting_object $16V &&
           //     $PlayerIsWearingBurglaryBalackava == 1 &&
           //     80DF: not actor $PLAYER_ACTOR driving 
           // then
              //  print_now 'POLH3' time 2000 flag 1
              //  010D: set_player $PLAYER_CHAR wanted_level_to 3 
                                       end 
                                    end    
                                 end   
                              end  
                           end
                             //0AE2: $PoliceCarAroundBobCat = random_vehicle_near_point 11@ 12@ 13@ in_radius 50.0 find_next 1 pass_wrecked 1
                        end
                    // end
                 // end
           //    end  
         //   end    
       //  end              


///////////////////////////////////////////////////////////////

// TEST MESSAGE TO VERIFY IT WORKS
//0AD1: show_formatted_text_highpriority "BobCatFloatSpeed: %f Collision force: %f" time 500 22@ 18@
//0AD1: show_formatted_text_highpriority "Car model: %d Speed: %f" time 500 25@ 22@
//0AD1: show_formatted_text_highpriority "Cop car: %d  Cop on foot: %d" time 500 $PoliceCarAroundBobCat $PolicePedAroundPlayer 
//////////////////
//0EA6: get_closest_cop_near_char 1@ 2@ 3@ radius 4@ alive 5@ in_car 6@ on_foot 7@ store_to 8@


    
    























////////////////////////////////////
01C0: $PlayerWantedL = player $PLAYER_CHAR wanted_level
////////////////////////////////////////----------------- IF I STOLE ALL THE 12 ITENS NEEDED. 
if and
 $StoredItens >= $MaxObjectsToSteal_Value &&
 $Dropoff_Message1 == 0 &&
 not $PlayerWantedL > 0
 then
  ////  REDIRECT TOWARDS FINISH MISSION AND DROP OBJECTS
   0ACA: show_text_box "~g~Now you got all the itens. Bring this pickup truck to the location! " 
   09E6: set_burglary_houses_accessible 0  
   $Dropoff_Message1 = 1
   03BC: $DropOffBobCat = create_sphere_at 1122.7758 -868.9712 43.1797 radius 2.0
   018A: $DropOffBobCat_Marker = create_checkpoint_at 1122.7758 -868.9712 43.1797
   jump @DropOffBobCat  
end
///////////---------------------********************








jump @GetInBobCat  //// Jump back to this section, because player haven't entered vehicle yet.
////////////////////////////////////////////////////////999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
////////////////////////////////////////////////////////999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
////////////////////////////////////////////////////////999999999999999999999999999999999999999999    G O S U B S                                                99999999999999999999999999999999999999


/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
:MissionFailedCheck
wait 0

// 1. Player died
if 0118: actor $PLAYER_ACTOR dead
then
    $MissionFailed = 1
    0AD1: show_formatted_text_highpriority "~r~PLAYER DIED!" time 4000
    jump @MissionFailed1
end

// 2. Bobcat wrecked
if 0119: car 3@ wrecked
then
    0164: disable_marker 4@
    $MissionFailed = 1
    0AD1: show_formatted_text_highpriority "~r~CAR WRECKED!" time 4000
    jump @MissionFailed1
end

// 3. Player busted
if 0741: actor $PLAYER_ACTOR busted
then
    $MissionFailed = 1
    0AD1: show_formatted_text_highpriority "~r~BUSTED!" time 4000
    jump @MissionFailed1
end

return

/////////////////////////////////////////////////////////////////////////////////////////
:MissionFailed1
wait 0

// 1. Eject player from car immediately if inside
if 00DB: actor $PLAYER_ACTOR in_car 3@
then
    0633: AS_actor $PLAYER_ACTOR exit_car
end

// 2. Start fade out
016A: fade 0 time 1000
wait 1000  

// 3. Display Mission Failed text
03E5: show_text_box 'M_FAIL' // "Mission Failed!"
00BA: show_text_styled GXT 'M_FAIL' time 5000 style 1

// 4. Clean up markers, spheres & UI while screen is black
0164: disable_marker 4@
0164: disable_marker $BurglaryPhoneRadarMarker
0164: disable_marker $DropOffBobCat_Marker
03BD: destroy_sphere $DropOffBobCat

clear_onscreen_counter $HouseStealer_Noise_I 
clear_onscreen_counter $HouseStealer_Escape_Time 
clear_onscreen_counter $Felony_Quantity 

// 5. Fade screen back in
016A: fade 1 time 1000
wait 1000 // Wait until fade-in finishes completely

// 6. Delete the car ONLY AFTER fade-in has completed
if 056E: car 3@ defined
then
    00A6: destroy_car 3@
    3@ = -1
end

$ONMISSION = 0
wait 500
jump @MissionCleanup

/////////////////////////////////////////////////////////////////////////////////////////
//                       M I S S I O N   C L E A N U P
/////////////////////////////////////////////////////////////////////////////////////////
:MissionCleanup
wait 0

// 1. CLEAR PANELS AND MENUS
if $CallMenuOpen == 1
then
    08DA: remove_panel $OpenCallMenu
    $CallMenuOpen = 0
end

if $BobCatTrunkMENU_Open == 1
then
    08DA: remove_panel $BobCatTrunkMENU
    $BobCatTrunkMENU_Open = 0
end

// 2. RESTORE PLAYER STATE
03BF: set_player $PLAYER_CHAR ignored_by_everyone 0
Player.CanMove($PLAYER_CHAR) = True
02AB: set_actor $PLAYER_ACTOR immunities BP 0 FP 0 EP 0 CP 0 MP 0

// Remove phone animations
0812: AS_actor $PLAYER_ACTOR perform_animation "phone_out" IFP "PED" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time 1
0729: AS_actor $PLAYER_ACTOR hold_cellphone 0

// Remove Balaclava if equipped
if $PlayerIsWearingBurglaryBalackava == 1
then
    give_player_clothes $PLAYER_CHAR textureCRC 0 modelCRC 0 bodypart 17 
    build_player_model $PLAYER_CHAR 
    $PlayerIsWearingBurglaryBalackava = 0
end

// 3. DESTROY ATTACHED & TEMPORARY OBJECTS
if 03CA: object 2@ exists
then 0108: destroy_object 2@
end

if 03CA: object 14@ exists
then 0108: destroy_object 14@
end

if 03CA: object $16V exists
then 
    0682: detach_object $16V 0.0 0.0 0.0 collision_detection 0
    0108: destroy_object $16V
    $16V = -1
end

// Delete physical objects stored in trunk
gosub @DeleteStolenObjects 

// 4. DESTROY CUTSCENE VEHICLES & ACTORS
if 056E: car $Boxville_Cutscene defined
then 
    00A6: destroy_car $Boxville_Cutscene
    $Boxville_Cutscene = -1
end

if 056D: actor 0@ defined
then 
    009B: destroy_actor 0@
    0@ = -1
end

if 056D: actor $BoxvilleDriver defined
then 
    009B: destroy_actor $BoxvilleDriver
    $BoxvilleDriver = -1
end

// If Bobcat still exists during normal cleanup (not from failure)
if 056E: car 3@ defined
then 
    00A6: destroy_car 3@
    3@ = -1
end

// 5. CLEANUP AUDIO
03D2: wav 1 ended 

// 6. RESET ALL MISSION STATE VARIABLES
$ONMISSION = 0 
$CalledUnknownCaller = 0 
$PHONE_IS_OPEN = 0
$Total_ObjectsToSteal = 0 
$CurrentSlot = 0 
$ItemAccepted = 0  
$StoredItens = 0 
$DisableBobCatMarker = 0 
$Dropoff_Message1 = 0 
$Dropoff_Message2 = 0 
$IsLiftingNow = 0 
$Message0 = 0

// Reset Item Quantities
$Television = 0 
$PlatesCups = 0 
$HIFI_MediaCenter = 0 
$VideoGame = 0 
$DVDPlayers = 0 
$RugsAndMatt = 0 
$Microwave = 0 
$MagazinesNovelsBooks = 0 

// Reset Slot Values
$ObjVal1 = 0 
$ObjVal2 = 0 
$ObjVal3 = 0 
$ObjVal4 = 0 
$ObjVal5 = 0 
$ObjVal6 = 0 
$ObjVal7 = 0 
$ObjVal8 = 0 

// Reset Trunk Object Variables
$BobCat_Trunk1_Obj = -1 
$BobCat_Trunk2_Obj = -1 
$BobCat_Trunk3_Obj = -1 
$BobCat_Trunk4_Obj = -1 
$BobCat_Trunk5_Obj = -1 
$BobCat_Trunk6_Obj = -1 
$BobCat_Trunk7_Obj = -1 
$BobCat_Trunk8_Obj = -1 
$BobCat_Trunk9_Obj = -1 
$BobCat_Trunk10_Obj = -1 
$BobCat_Trunk11_Obj = -1 
$BobCat_Trunk12_Obj = -1 

// Reset Burglary / Felony States
$HouseStealer_Escape_Active = 0
$MustEscape = 0
$Reset_BurglaryH_Vars = 0
$HouseStealer_Noise_I = 0
$HouseStealer_Noise_F = 0.0
$HouseStealer_Escape_TimerStarted = 0
$HouseStealer_EscapeTime_Crescent_Guard = 0
$HouseStealer_Escape_Time = -1
$Felony_Quantity = 0
$BobCatSpeed = 0

// 7. RESTORE WORLD BEHAVIOR
09E6: set_burglary_houses_accessible 0
0A14: disable_respray_garages 0  

wait 60000   
jump @Restart
/////////////////////////////////////////////////////////////////////////////////////////////////////////







/////////////////////////////////////////////////////////////////////////////////////////11111111111111111111111111111111//5555555555555555555555555555555555555555555555555555/
/////////////////////////////////
:OpenCellphone
wait 0 
gosub @MissionFailedCheck
///////////////////------------------------
$PHONE_IS_OPEN = 1
03BF: set_player $PLAYER_CHAR ignored_by_everyone 1
Player.CanMove($PLAYER_CHAR) = False

// Request the cellphone model and animations
0247: request_model 330 // Cellphone Model
 if
    0248: not model 330 available
       wait 0
038B: load_requested_models

04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.02 0.01 0.0
wait 100

///////CJ'S CELLPHONE CODE WAS HERE. RESTORE IF NEEDED!! ----------------------------<<<<<<<<<<<<<<<<<<<<<<


0729: AS_actor $PLAYER_ACTOR hold_cellphone 1
wait 1000
0605: actor $PLAYER_ACTOR apply_animation "phone_talk" IFP "PED" 4.0 loop 1 lockX 0 lockY 0 lockF 0 time -1

// Loop the "Talking on phone" animation
/// 0605: actor $PLAYER_ACTOR apply_animation "phone_talk" IFP "PED" 4.0 loop 1 lockX 0 lockY 0 lockF 0 time -1
jump @OpenCallMenu
//////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////   O P E N  C A L L  - M E N U    ///////////////////////////////<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
:OpenCallMenu
wait 0 
gosub @MissionFailedCheck
///////////////////------------------------
0ACA: show_text_box "~g~Press ~b~Backspace to cancel and close menu."
$CallMenuOpen = 1

//////////////////////////////////////////////////////////////////////////////////CREATE THE BACK OF THE VAN MENU TO CHOOSE A BOX TO DELIVER
08D4: $OpenCallMenu = create_panel_with_title 'TELP' position 200.0 330.0 width 140.0  columns 1 interactive 1 background 1 alignment 0
08DB: set_panel $OpenCallMenu column 0 header 'DUMMY' data 'TELP2' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY'

///Activate rows
08D9: set_panel $OpenCallMenu row 0 enable 1

$SelectedChoiceRow = 0

///////////////////////////////////////////////////-------------------------
:OpenCallMenu2
wait 0 

//----------------------------CHECK FOR MISSION FAILED
gosub @MissionFailedCheck
////////------------------

08D8: $SelectedChoiceRow = panel $OpenCallMenu selected_row

/////////////////////////////////
if
0AB0: key_pressed 8  ///backspace
then
    gosub @CloseOpenCallMenuPanel
    jump @GetInBobCat
end    
/////////////////////////////

 
 //////////////////////////////////////////////////////// C A L L  C O N T A C T
if     
  0AB0: key_pressed 160 // Shift  
  then
   if
    $SelectedChoiceRow == 0 //// Give call
    then
       $CalledUnknownCaller = 1 
        gosub @CloseOpenCallMenuPanel
        wait 100
        jump @CallUnknownCaller
      end  
   end     

 
  
/////////////////////////////////////////////////////////////
jump @OpenCallMenu2
///--------------------------------------------------------------------------


/////////////////////////////////////////////////////////////////  CLOSE TELEPHONE MENU
:CloseOpenCallMenuPanel
wait 0 
08DA: remove_panel $OpenCallMenu   
$CallMenuOpen = 0
// Play the "Putting away phone" animation
0812: AS_actor $PLAYER_ACTOR perform_animation "phone_out" IFP "PED" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time 1
0729: AS_actor $PLAYER_ACTOR hold_cellphone 0
if 03CA: object 14@ exists
    then  
        0108: destroy_object 14@
        // Clean up models from memory
        0249: release_model 330        
end
14@ = -1
03BF: set_player $PLAYER_CHAR ignored_by_everyone 0
Player.CanMove($PLAYER_CHAR) = True
return
//////////////////////////////////////////




///////////////////////////////////////// Calls unknown called for first time when near vehicle, so he will say random things to steal.
:CallUnknownCaller
wait 0 
//----------------------------CHECK FOR MISSION FAILED
gosub @MissionFailedCheck


//////////////// PICK RANDOM OBJECTS TO STEAL
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////------------------------------------------

:PickRandomItemsLoop
wait 0
gosub @MissionFailedCheck
if 
    $Total_ObjectsToSteal == $MaxObjectsToSteal_Value
then
    jump @MapItemsToSlots // Once we have 6 items,or more, map them to the display slots!
end

// Generate a random number between 1 and 15
0209: $Which_Obj_Category_To_Steal_INTRange = random_int_in_ranges 1 8 //// ALWAYS CHANGE WHEN CREATE MORE OR DELETE MORE OBJECTS!  

if $Which_Obj_Category_To_Steal_INTRange == 1
then $Television += 1
end

if $Which_Obj_Category_To_Steal_INTRange == 2
then $PlatesCups += 1
end

if $Which_Obj_Category_To_Steal_INTRange == 3
then $HIFI_MediaCenter += 1
end

if $Which_Obj_Category_To_Steal_INTRange == 4
then
   $VideoGame += 1
end

if $Which_Obj_Category_To_Steal_INTRange == 5
then $DVDPlayers += 1
end

if $Which_Obj_Category_To_Steal_INTRange == 6
then $RugsAndMatt += 1
end

if $Which_Obj_Category_To_Steal_INTRange == 7
then $Microwave += 1
end

if $Which_Obj_Category_To_Steal_INTRange == 8
then $MagazinesNovelsBooks += 1
end


$Total_ObjectsToSteal += 1
jump @PickRandomItemsLoop



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////------------------------------------------
// MAP THE CHOSEN ITEMS TO THE 6 SLOTS
///////////////////////////////////////////////////
:MapItemsToSlots
wait 0
$CurrentSlot = 1 // Start at slot 1

// We check every item. If it has a quantity > 0, we send it to the assignment subroutine
if $Television > 0
then 
    $TempObjVar = $Television
   // $TempObjString = $EletrString1
    0D4D: copy_string "Television" to $TempObjString
    gosub @AssignToNextSlot
end

if $PlatesCups > 0
then 
    $TempObjVar = $PlatesCups
    // $TempObjString = $EletrString2
    0D4D: copy_string "Plate/Bowl" to $TempObjString
    gosub @AssignToNextSlot
end

if $HIFI_MediaCenter > 0
then 
    $TempObjVar = $HIFI_MediaCenter
    // $TempObjString = $EletrString3
    0D4D: copy_string "Hi-Fi" to $TempObjString
    gosub @AssignToNextSlot
end

if
 $VideoGame > 0
then 
    $TempObjVar = $VideoGame
    // $TempObjString = $EletrString4
    0D4D: copy_string "Game Console" to $TempObjString
    gosub @AssignToNextSlot
end

if $DVDPlayers > 0
then 
    $TempObjVar = $DVDPlayers
    // $TempObjString = $EletrString5
    0D4D: copy_string "DVD Player" to $TempObjString
    gosub @AssignToNextSlot
end

if $RugsAndMatt > 0
then 
    $TempObjVar = $RugsAndMatt
    // $TempObjString = $EletrString6
    0D4D: copy_string "Rug/Carpet" to $TempObjString
    gosub @AssignToNextSlot
end

if $Microwave > 0
then 
    $TempObjVar = $Microwave
    // $TempObjString = $EletrString7
    0D4D: copy_string "Microwave" to $TempObjString
    gosub @AssignToNextSlot
end

if $MagazinesNovelsBooks > 0
then 
    $TempObjVar = $MagazinesNovelsBooks
    // $TempObjString = $EletrString8
    0D4D: copy_string "Book/Magazine" to $TempObjString
    gosub @AssignToNextSlot
end


jump @ContinueDialogWithUnknownCaller

 /////////////////////////////////////////////////////////////////////////////////////// MADE BY: ANDREW THIAGO
///////////////////////////////////////////////////////////////////////////////////////////////////////------------------------------------------
// SUBROUTINE: ASSIGN TO THE NEXT AVAILABLE SLOT
///////////////////////////////////////////////////
:AssignToNextSlot
wait 0
if $CurrentSlot == 1
then 
    $ObjVal1 = $TempObjVar
    
    
    $ObjNam1 = $TempObjString
    wait 50
    $TempObjVar = -1
end
if $CurrentSlot == 2
then 
    $ObjVal2 = $TempObjVar
    
    
    $ObjNam2 = $TempObjString
    wait 50
    $TempObjVar = -1
end
if $CurrentSlot == 3
then 
    $ObjVal3 = $TempObjVar
    
    
    $ObjNam3 = $TempObjString
    wait 50
    $TempObjVar = -1
end
if $CurrentSlot == 4
then 
    $ObjVal4 = $TempObjVar
    
    
    $ObjNam4 = $TempObjString
    wait 50
    $TempObjVar = -1
end
if $CurrentSlot == 5
then 
    $ObjVal5 = $TempObjVar
    
    
    $ObjNam5 = $TempObjString
    wait 50
    $TempObjVar = -1
end
if $CurrentSlot == 6
then 
    $ObjVal6 = $TempObjVar
    
    
    $ObjNam6 = $TempObjString
    wait 50
    $TempObjVar = -1
end
if $CurrentSlot == 7
then 
    $ObjVal7 = $TempObjVar
    
    
    $ObjNam7 = $TempObjString
    wait 50
    $TempObjVar = -1
end
if $CurrentSlot == 8
then 
    $ObjVal8 = $TempObjVar
     
    
    $ObjNam8 = $TempObjString
    wait 50
    $TempObjVar = -1
end



$CurrentSlot += 1
return

///////////////////////////////////////////////////////////////////////////////////////////////////////------------------------------------------

:ContinueDialogWithUnknownCaller
wait 0 
gosub @MissionFailedCheck

/////--------------------
if 
  0AB0: key_pressed 9
then
  //////////// CLOSE CELLPHONE
  gosub @CloseOpenCallMenuPanel
  0812: AS_actor $PLAYER_ACTOR perform_animation "phone_out" IFP "PED" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time 1
  0729: AS_actor $PLAYER_ACTOR hold_cellphone 0
  //lock_car_doors 3@ mode 0
  jump @UnlockBobCat
end  
   /////--------------------
   
///////////////////------------------------
0AD1: show_formatted_text_highpriority "~w~...I need you to steal the following objects for me:" time 2350
//lock_car_doors 3@ mode 0
wait 2350

////////////////////////----------------------
gosub @WhichItensToSteal_TextBox    //// SHOW OBJECTS PLAYER NEED TO STEAL OR.."BORROW" AT THE MOMENT. 
////////////////////////--------------

/////--------------------
if 
  0AB0: key_pressed 9
then
  //////////// CLOSE CELLPHONE
  gosub @CloseOpenCallMenuPanel
  0812: AS_actor $PLAYER_ACTOR perform_animation "phone_out" IFP "PED" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time 1
  0729: AS_actor $PLAYER_ACTOR hold_cellphone 0
 // lock_car_doors 3@ mode 0

//lock_car_doors 3@ mode 0
  jump @UnlockBobCat
end  

0AD1: show_formatted_text_highpriority "~w~Press the damm TAB key to check which objects you must steal. I won't accept objects i didn't ask for!" time 4500

/////--------------------
if 
  0AB0: key_pressed 9
then
  //////////// CLOSE CELLPHONE
  gosub @CloseOpenCallMenuPanel
  0812: AS_actor $PLAYER_ACTOR perform_animation "phone_out" IFP "PED" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time 1
  0729: AS_actor $PLAYER_ACTOR hold_cellphone 0
  //lock_car_doors 3@ mode 0
  jump @UnlockBobCat
end  
   /////--------------------
   
wait 1000

//////////// CLOSE CELLPHONE
gosub @CloseOpenCallMenuPanel

// 0519: set_car 3@ locked 0

/////--------------------
if 
  0AB0: key_pressed 9
then
  //////////// CLOSE CELLPHONE
  gosub @CloseOpenCallMenuPanel
  0812: AS_actor $PLAYER_ACTOR perform_animation "phone_out" IFP "PED" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time 1
  0729: AS_actor $PLAYER_ACTOR hold_cellphone 0
  0519: set_car 3@ locked 0
  jump @UnlockBobCat
end  
   /////--------------------
   
wait 3300
//lock_car_doors 3@ mode 0
0ACA: show_text_box "~y~When you pick up a object, take it to the back of your Bobcat. Press ~r~G ~y~to open the trunk menu."
lock_car_doors 3@ mode 0
/////--------------------
if 
  0AB0: key_pressed 9
then
  //////////// CLOSE CELLPHONE
  gosub @CloseOpenCallMenuPanel
  0812: AS_actor $PLAYER_ACTOR perform_animation "phone_out" IFP "PED" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time 1
  0729: AS_actor $PLAYER_ACTOR hold_cellphone 0
  jump @UnlockBobCat
end  
   /////--------------------
   
wait 4000

:UnlockBobCat
wait 0
0ACA: show_text_box "~y~Then, load the stuff in by pressing ~r~SHIFT."
//wait 1000
lock_car_doors 3@ mode 0
wait 50
08DA: remove_panel $OpenCallMenu   
$CallMenuOpen = 0
$CalledUnknownCaller = 1
0812: AS_actor $PLAYER_ACTOR perform_animation "phone_out" IFP "PED" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time 1
wait 5
0729: AS_actor $PLAYER_ACTOR hold_cellphone 0

jump @GetInBobCat
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////     T R U N K  M E N U                                            //////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
:BobCatTrunkMENU /////////
wait 0 
$ItemAccepted = 0 
///////////////////------------------------
0ACA: show_text_box "~g~Press ~b~Backspace to cancel and close menu."
0519: set_car 3@ locked 1 
$BobCatTrunkMENU_Open = 1
$BobCatTrunk = 1
03BF: set_player $PLAYER_CHAR ignored_by_everyone 1
Player.CanMove($PLAYER_CHAR) = False

//////////////////////////////////////////////////////////////////////////////////CREATE THE BACK OF THE VAN MENU TO CHOOSE A BOX TO DELIVER
08D4: $BobCatTrunkMENU = create_panel_with_title 'DUMMY' position 29.0 200.0 width 150.0 columns 1 interactive 1 background 1 alignment 0
08DB: set_panel $BobCatTrunkMENU column 0 header 'BMN1' data 'BMN2' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY'

///Activate rows
08D9: set_panel $BobCatTrunkMENU row 0 enable 1
08D9: set_panel $BobCatTrunkMENU row 1 enable 1


///////////////////////////////////////////////////-------------------------
$SelectedBobCatTrunkRow = 0
/////////////////////////////////////////////////
08A6: set_car 3@ door $BobCatTrunk rotation_to 1.0

/////////////////////
:BobCatTrunkMENU2
wait 0

///////////////////------------------------
08D8: $SelectedBobCatTrunkRow = panel $BobCatTrunkMENU selected_row


/////////////////////////////////
if
0AB0: key_pressed 8  ///backspace
then
    jump @CloseBobCatTrunkMENU
end    
/////////////////////////////
 //////////////  IT'S IMPORTANT TO PUT THE ACTIONS UNDER KEYPRESSES AND NOT KEY PRESSES FOR EACH OPTION THAT MIGHT EXISTS!////////////----
 
 //////////////////////////////////////////////////////// IS STOLEN OBJECT WANTED? 

if     
  0AB0: key_pressed 160 // Shift
 then
    // --- OPTION: CHECK IF HOLDING OBJECT IS WANTED BY CONTACT-
    // --- FIX: GTE MENU TO CHECK $16V INSTEAD OF 8@ SO KEY PRESS IS NEVER BLOCKED ---
    if 
      $SelectedBobCatTrunkRow == 0
     then
       if 
        0737: actor $PLAYER_ACTOR lifting_object $16V
       then
        0984: 9@ = object $16V model // 
        jump @BobCat_TrunkMENU
    end
   end
end

jump @BobCatTrunkMENU2
////////////////////////////////////////////////////////////////-------------------------------------------------------

////////////////////////////////////////////////////CLOSE BobCat Trunk MENU
:CloseBobCatTrunkMENU 
wait 0
08DA: remove_panel $BobCatTrunkMENU   
$BobCatTrunkMENU_Open = 0
$BobCatTrunk_Open = 0
03BF: set_player $PLAYER_CHAR ignored_by_everyone 0
0519: set_car 3@ locked 0
Player.CanMove($PLAYER_CHAR) = True
08A6: set_car 3@ door $BobCatTrunk rotation_to 0.0
jump @GetInBobCat

/////////////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                                     //    C H E C K  T R U N K   
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////22222222222222222222222222222222222222222222222
:BobCat_TrunkMENU
wait 0 
gosub @MissionFailedCheck
///////////////////------------------------
0984: 9@ = object $16V model // 
$ItemAccepted = 0 

         
// Do not get the model yet! First check if $16V is valid and being held!
if and
 $IsLiftingNow == 0 &&
 0737: not actor $PLAYER_ACTOR lifting_object $16V /// 16@ before
 // 0737: not actor $PLAYER_ACTOR lifting_object $16V
then
    0AD1: show_formatted_text_highpriority "~r~You're not holding an object!" time 2100
    wait 1500
    jump @CloseBobCatTrunkMENU 
end

// 1. Send the carried ID to our identifier subroutine
gosub @IdentifyStolenObject 


// Check Slot 1
if and
    $PickedCategory == $ObjNam1
    $ObjVal1 > 0
then
    $ObjVal1 -= 1   // Decrease the amount we still need to steal!
    $ItemAccepted = 1
    $StoredItens +=1
       jump @BobCat_UpdateTrunkVisuals
end

// Check Slot 2
if and
    $ItemAccepted == 0
    $PickedCategory == $ObjNam2
    $ObjVal2 > 0
then
    $ObjVal2 -= 1
    $ItemAccepted = 1
    $StoredItens +=1
       jump @BobCat_UpdateTrunkVisuals
end

// Check Slot 3
if and
    $ItemAccepted == 0
    $PickedCategory == $ObjNam3
    $ObjVal3 > 0
then
    $ObjVal3 -= 1
    $ItemAccepted = 1
    $StoredItens +=1
       jump @BobCat_UpdateTrunkVisuals
end

// Check Slot 4
if and
    $ItemAccepted == 0 
    $ObjVal4 > 0
    $PickedCategory == $ObjNam4     
then
    $ItemAccepted = 1
    $StoredItens +=1
    $ObjVal4 -= 1
       jump @BobCat_UpdateTrunkVisuals
end

// Check Slot 5
if and
    $ItemAccepted == 0
    $PickedCategory == $ObjNam5
    $ObjVal5 > 0
then
    $ObjVal5 -= 1
    $ItemAccepted = 1
    $StoredItens +=1
       jump @BobCat_UpdateTrunkVisuals
end

// Check Slot 6
if and
    $ItemAccepted == 0
    $PickedCategory == $ObjNam6
    $ObjVal6 > 0
then
    $ObjVal6 -= 1
    $ItemAccepted = 1
    $StoredItens +=1
       jump @BobCat_UpdateTrunkVisuals
end

// Check Slot 7
if and
    $ItemAccepted == 0
    $PickedCategory == $ObjNam7
    $ObjVal7 > 0
then
    $ObjVal7 -= 1
    $ItemAccepted = 1
    $StoredItens +=1
       jump @BobCat_UpdateTrunkVisuals
end

// Check Slot 8
if and
    $ItemAccepted == 0
    $PickedCategory == $ObjNam8
    $ObjVal8 > 0
then
    $ObjVal8 -= 1
    $ItemAccepted = 1
    $StoredItens +=1
       jump @BobCat_UpdateTrunkVisuals
end

////////////////////////////////////////-------------------------

// 3. Final Result: Did we need it or not?
if 
  $ItemAccepted == 1
 then
    08DA: remove_panel $BobCatTrunkMENU   
    $BobCatTrunkMENU_Open = 0
    $BobCatTrunk_Open = 0
    08DA: remove_panel $BobCatTrunkMENU   
    03BF: set_player $PLAYER_CHAR ignored_by_everyone 0
    Player.CanMove($PLAYER_CHAR) = True 
    //////////////////////////////////////////
   // jump @BobCat_UpdateTrunkVisuals
else
    0AD1: show_formatted_text_highpriority "~r~He's not looking for this object this time." time 2000
    // (Leave the object in CJ's hands or drop it on the floor)
    08DA: remove_panel $BobCatTrunkMENU   
    $BobCatTrunkMENU_Open = 0
    $BobCatTrunk_Open = 0
    jump @CloseBobCatTrunkMENU 
end

if 
  $PickedCategory == "Invalid"
then
    0AD1: show_formatted_text_highpriority "~r~This is not a valid object!" time 3000
    jump @CloseBobCatTrunkMENU 
end


jump @CloseBobCatTrunkMENU
//////////////////////////////////////////////////////////////////////////////////////////////////88888888888888888888888888888888888888888888888888888


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Step 1: Converting the Model ID to a Category String

// Input: 9@ = The Model ID of the object CJ is trying to put in the Bobcat
// Output: $PickedCategory = The string name of the object (or "Invalid")
:IdentifyStolenObject
wait 0


$PickedCategory = "Invalid" // Default state

// --- TELEVISIONS (Split into groups of 7 max) ---
if or
    9@ == 1781
    9@ == 14772
    9@ == 1518
    9@ == 1747
    9@ == 1751
    9@ == 1752
    9@ == 2648
    then 
       //$PickedCategory = $EletrString1  // "Television"
       0D4D: copy_string "Television" to $PickedCategory
end   
if or 
    9@ == 1717
    9@ == 2596
    9@ == 2595
    9@ == 2322
    9@ == 1429
    9@ == 2318
    9@ == 2320
   then
       //$PickedCategory = $EletrString1  // "Television"
       0D4D: copy_string "Television" to $PickedCategory   
end   
if or    
    9@ == 2312
    9@ == 1748
    9@ == 1749
    9@ == 2317
    9@ == 2316    
    then
       //$PickedCategory = $EletrString1  // "Television"
       0D4D: copy_string "Television" to $PickedCategory
end
if or
    9@ == 1750
    9@ == 1786
    9@ == 1791
    9@ == 1792
    9@ == 19786
    9@ == 19787
    9@ == 2700
    then
       //$PickedCategory = $EletrString1  // "Television"
       0D4D: copy_string "Television" to $PickedCategory
end

// --- $PlatesCups --- // Plates, cups, folks, knives
if or
 9@ == 2830
 9@ == 2831
 9@ == 2832
 9@ == 2848
 9@ == 2849
 9@ == 2850
    then
       // $PickedCategory = $EletrString2
       0D4D: copy_string "Plate/Bowl" to $PickedCategory
end 
if or
 9@ == 2851
 9@ == 2862
 9@ == 2863
 9@ == 2864
 9@ == 2865
    then
      // $PickedCategory = $EletrString2
       0D4D: copy_string "Plate/Bowl" to $PickedCategory
end 
if or
 9@ == 11715 
 9@ == 11716 
 9@ == 2812
 9@ == 2822
 9@ == 2829
    then
      // $PickedCategory = $EletrString2
       0D4D: copy_string "Plate/Bowl" to $PickedCategory
end

// --- HI-FI MEDIA CENTERS ---
if or
    9@ == 1809
    9@ == 1839
    9@ == 2101
    9@ == 2226
    9@ == 2102
    9@ == 2103
    then
       // $PickedCategory = $EletrString3
       0D4D: copy_string "HI-FI" to $PickedCategory
end


// --- VIDEO GAMES ---
if or
    9@ == 1718
    9@ == 2028
    9@ == 1719
    then 
       //$PickedCategory = $EletrString4
       0D4D: copy_string "Game Console" to $PickedCategory
end


// --- DVD PLAYERS ---
if or
9@ == 1782
9@ == 1783
9@ == 1784
9@ == 1787
9@ == 1788
9@ == 1790
    then
      //$PickedCategory = $EletrString5
      0D4D: copy_string "DVD Player" to $PickedCategory
end


// --- $Rugs ---
if or
 9@ == 2834
 9@ == 2836
 9@ == 2841
 9@ == 2842
 9@ == 2847
 9@ == 11737
 9@ == 2631
    then
      //$PickedCategory = $EletrString6
      0D4D: copy_string "Rug/Carpet" to $PickedCategory     
end
if or
 9@ == 2632
 9@ == 2815
 9@ == 2817
 9@ == 2818
 9@ == 2833
 9@ == 2835
 9@ == 1828
    then 
      //$PickedCategory = $EletrString6
      0D4D: copy_string "Rug/Carpet" to $PickedCategory 
end


// --- MICROWAVE ---
if 
  9@ == 2149
    then
     //$PickedCategory = $EletrString7
     0D4D: copy_string "Microwave" to $PickedCategory 
end

// --- $MagazinesNovelsBooks ---
if or
 9@ == 2813
 9@ == 2816
 9@ == 2824
 9@ == 2826
 9@ == 2827
    then
     //$PickedCategory = $EletrString8
     0D4D: copy_string "Book/Magazine" to $PickedCategory 
end 
if or
 9@ == 2852
 9@ == 2853
 9@ == 2854
 9@ == 2855
    then
     //$PickedCategory = $EletrString8
     0D4D: copy_string "Book/Magazine" to $PickedCategory 
end


return
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666--------------
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

:BobCat_UpdateTrunkVisuals
wait 0
0984: 9@ = object $16V model 
//////////--------------------------
if
    $BobCat_Trunk1 == -1
then
    // --- DETACH, DESTROY, AND RESET THE CORRECT CARRIED OBJECT HANDLE ($16V) ---  
    if
      $16V > -1
     then
        0682: detach_object $16V 0.0 0.0 0.0 collision_detection 0
        wait 50
        0107: $BobCat_Trunk1_Obj = create_object 9@ at -0.55 -0.55 -0.2
        0681: attach_object $BobCat_Trunk1_Obj to_car 3@ with_offset -0.55 -0.55 -0.2 rotation 0.0 0.0 0.0
        wait 50
      0108: destroy_object $16V
        wait 50
        $16V = -1
        9@ = -1
        $IsLiftingNow = 0
        $BobCat_Trunk1 = 1
        0AD1: show_formatted_text_highpriority "~g~Object loaded into the truck." time 2000
       // 0249: release_model 9@
        wait 500
        jump @CloseBobCatTrunkMENU
    end         
else

if
    $BobCat_Trunk2 == -1
then
    // --- DETACH, DESTROY, AND RESET THE CORRECT CARRIED OBJECT HANDLE ($16V) ---  
    if
      $16V > -1
     then
        0682: detach_object $BobCat_Trunk2_Obj 0.0 0.0 0.0 collision_detection 0
        wait 50
        0107: $BobCat_Trunk2_Obj = create_object 9@ at 0.0 -0.80 -0.2
        0681: attach_object $BobCat_Trunk2_Obj to_car 3@ with_offset 0.0 -0.80 -0.2 rotation 0.0 0.0 0.0
        wait 100
        0108: destroy_object $16V
        wait 5
        $16V = -1
        9@ = -1
        $TrunkObjectZ = 0.0
        $IsLiftingNow = 0
        $BobCat_Trunk2 = 1
        0AD1: show_formatted_text_highpriority "~g~Object loaded into the truck." time 2000
       // 0249: release_model 9@
        wait 500        
        jump @CloseBobCatTrunkMENU
    end         
else

if
    $BobCat_Trunk3 == -1
then
    // --- DETACH, DESTROY, AND RESET THE CORRECT CARRIED OBJECT HANDLE ($16V) ---  
    if
      $16V > -1
     then
        0682: detach_object $BobCat_Trunk3_Obj 0.0 0.0 0.0 collision_detection 0
        wait 50
        0107: $BobCat_Trunk3_Obj = create_object 9@ at 0.45 -0.80 -0.2
        0681: attach_object $BobCat_Trunk3_Obj to_car 3@ with_offset 0.45 -0.80 -0.2 rotation 0.0 0.0 0.0
        wait 100
        0108: destroy_object $16V
        wait 5
       $16V = -1
        9@ = -1
        $TrunkObjectZ = 0.0
        $IsLiftingNow = 0
        $BobCat_Trunk3 = 1
        0AD1: show_formatted_text_highpriority "~g~Object loaded into the truck." time 2000
      //  0249: release_model 9@
        wait 500        
        jump @CloseBobCatTrunkMENU
    end         
else

if
    $BobCat_Trunk4 == -1
then
    // --- DETACH, DESTROY, AND RESET THE CORRECT CARRIED OBJECT HANDLE ($16V) ---  
    if
      $16V > -1
     then
        0682: detach_object $16V 0.0 0.0 0.0 collision_detection 0
        wait 50
        0107: $BobCat_Trunk4_Obj = create_object 9@ at -0.45 -1.30 -0.2
        0681: attach_object $BobCat_Trunk4_Obj to_car 3@ with_offset -0.45 -1.30 -0.2 rotation 0.0 0.0 0.0
        wait 100
      0108: destroy_object $16V
        wait 5
        $16V = -1
        9@ = -1
        $TrunkObjectZ = 0.0
        $IsLiftingNow = 0
        $BobCat_Trunk4 = 1
        0AD1: show_formatted_text_highpriority "~g~Object loaded into the truck." time 2000
     //   0249: release_model 9@
        wait 500        
        jump @CloseBobCatTrunkMENU
    end         
else

if
    $BobCat_Trunk5 == -1
then
    // --- DETACH, DESTROY, AND RESET THE CORRECT CARRIED OBJECT HANDLE ($16V) ---  
    if
      $16V > -1
     then
        0682: detach_object $16V 0.0 0.0 0.0 collision_detection 0
        wait 50
        0107: $BobCat_Trunk5_Obj = create_object 9@ at 0.00 -1.30 -0.2 
        0681: attach_object $BobCat_Trunk5_Obj to_car 3@ with_offset0. 0.00 -1.30 -0.2 rotation 0.0 0.0 0.0
        wait 100
        0108: destroy_object $16V
        wait 5
        $16V = -1
        9@ = -1
        $TrunkObjectZ = 0.0
        $IsLiftingNow = 0
        $BobCat_Trunk5 = 1
        0AD1: show_formatted_text_highpriority "~g~Object loaded into the truck." time 2000
      //  0249: release_model 9@
        wait 500        
        jump @CloseBobCatTrunkMENU
    end         
else

if
    $BobCat_Trunk6 == -1
then
    // --- DETACH, DESTROY, AND RESET THE CORRECT CARRIED OBJECT HANDLE ($16V) ---
    if
        $16V > -1
    then
        0682: detach_object $16V 0.0 0.0 0.0 collision_detection 0
        wait 50
        0107: $BobCat_Trunk6_Obj = create_object 9@ at 0.45 -1.30 -0.2
        0681: attach_object $BobCat_Trunk6_Obj to_car 3@ with_offset 0.45 -1.30 -0.2 rotation 0.0 0.0 0.0
        wait 100
      0108: destroy_object $16V
        wait 5
        $16V = -1
        9@ = -1
        $TrunkObjectZ = 0.0
        $IsLiftingNow = 0
        $BobCat_Trunk6 = 1
        0AD1: show_formatted_text_highpriority "~g~Object loaded into the truck." time 2000
      //  0249: release_model 9@
       // wait 500
        jump @CloseBobCatTrunkMENU
    end
else


if
    $BobCat_Trunk7 == -1
then
    // --- DETACH, DESTROY, AND RESET THE CORRECT CARRIED OBJECT HANDLE ($16V) ---
    if
        $16V > -1
    then
        0682: detach_object $16V 0.0 0.0 0.0 collision_detection 0
        wait 50
        0107: $BobCat_Trunk7_Obj = create_object 9@ at -0.45 -1.80 -0.2
        0681: attach_object $BobCat_Trunk7_Obj to_car 3@ with_offset -0.45 -1.80 -0.2 rotation 0.0 0.0 0.0
        wait 100
        0108: destroy_object $16V
        wait 20
        $16V = -1
        9@ = -1
        $TrunkObjectZ = 0.0
        $IsLiftingNow = 0
        $BobCat_Trunk1 = 7
        0AD1: show_formatted_text_highpriority "~g~Object loaded into the truck." time 2000
      //  0249: release_model 9@
        wait 500
        jump @CloseBobCatTrunkMENU
    end
else


if
    $BobCat_Trunk8 == -1
then
    // --- DETACH, DESTROY, AND RESET THE CORRECT CARRIED OBJECT HANDLE ($16V) ---
    if
        $16V > -1
    then
        0682: detach_object $16V 0.0 0.0 0.0 collision_detection 0
        wait 50
        0107: $BobCat_Trunk8_Obj = create_object 9@ at 0.00 -1.80 -0.2
        0681: attach_object $BobCat_Trunk8_Obj to_car 3@ with_offset 0.00 -1.80 -0.2 rotation 0.0 0.0 0.0
        wait 100
        0108: destroy_object $16V
        wait 20
        $16V = -1
        9@ = -1
        $TrunkObjectZ = 0.0
        $IsLiftingNow = 0
        $BobCat_Trunk8 = 1
        0AD1: show_formatted_text_highpriority "~g~Object loaded into the truck." time 2000
      //  0249: release_model 9@
        wait 500
        jump @CloseBobCatTrunkMENU
    end
else


if
    $BobCat_Trunk9 == -1
then
    // --- DETACH, DESTROY, AND RESET THE CORRECT CARRIED OBJECT HANDLE ($16V) ---
    if
        $16V > -1
    then
        0682: detach_object $16V 0.0 0.0 0.0 collision_detection 0
        wait 50
        0107: $BobCat_Trunk9_Obj = create_object 9@ at 0.45 -1.80 -0.2
        0681: attach_object $BobCat_Trunk9_Obj to_car 3@ with_offset 0.45 -1.80 -0.2 rotation 0.0 0.0 0.0
        wait 100
        0108: destroy_object $16V
        wait 20
        $16V = -1
        9@ = -1
        $TrunkObjectZ = 0.0
        $IsLiftingNow = 0
        $BobCat_Trunk1 = 9
        0AD1: show_formatted_text_highpriority "~g~Object loaded into the truck." time 2000
      //  0249: release_model 9@
        wait 500
        jump @CloseBobCatTrunkMENU
    end
else


if
    $BobCat_Trunk10 == -1
then
    // --- DETACH, DESTROY, AND RESET THE CORRECT CARRIED OBJECT HANDLE ($16V) ---
    if
        $16V > -1
    then
        0682: detach_object $16V 0.0 0.0 0.0 collision_detection 0
        wait 50
        0107: $BobCat_Trunk10_Obj = create_object 9@ at -0.45 -2.30 -0.2
        0681: attach_object $BobCat_Trunk10_Obj to_car 3@ with_offset -0.45 -2.30 -0.2 rotation 0.0 0.0 0.0
        wait 100
        0108: destroy_object $16V
        wait 5
        $16V = -1
        9@ = -1
        $TrunkObjectZ = 0.0
        $IsLiftingNow = 0
        $BobCat_Trunk10 = 1
        0AD1: show_formatted_text_highpriority "~g~Object loaded into the truck." time 2000
     //   0249: release_model 9@
        wait 500
        jump @CloseBobCatTrunkMENU
    end
else


if
    $BobCat_Trunk11 == -1
then
    // --- DETACH, DESTROY, AND RESET THE CORRECT CARRIED OBJECT HANDLE ($16V) ---
    if
        $16V > -1
    then
        0682: detach_object $16V 0.0 0.0 0.0 collision_detection 0
        wait 50
        0107: $BobCat_Trunk11_Obj = create_object 9@ at 0.00 -2.30 -0.2
        0681: attach_object $BobCat_Trunk11_Obj to_car 3@ with_offset 0.00 -2.30 -0.2 rotation 0.0 0.0 0.0
        wait 100
        0108: destroy_object $16V
        wait 5
        $16V = -1
        9@ = -1
        $TrunkObjectZ = 0.0
        $IsLiftingNow = 0
        $BobCat_Trunk11 = 1 
        0AD1: show_formatted_text_highpriority "~g~Object loaded into the truck." time 2000
      //  0249: release_model 9@
        wait 500
        jump @CloseBobCatTrunkMENU
    end
else


if
    $BobCat_Trunk12 == -1
then
    // --- DETACH, DESTROY, AND RESET THE CORRECT CARRIED OBJECT HANDLE ($16V) ---
    if
        $16V > -1
    then
        0682: detach_object $16V 0.0 0.0 0.0 collision_detection 0
        wait 50
        0107: $BobCat_Trunk12_Obj = create_object 9@ at 0.45 -2.30 -0.2
        0681: attach_object $BobCat_Trunk12_Obj to_car 3@ with_offset 0.45 -2.30 -0.2 rotation 0.0 0.0 0.0
        wait 100
        0108: destroy_object $16V
        wait 5
        $16V = -1
        9@ = -1
        $TrunkObjectZ = 0.0
        $IsLiftingNow = 0
        $BobCat_Trunk12 = 1
        0AD1: show_formatted_text_highpriority "~g~Object loaded into the truck." time 2000
      //  0249: release_model 9@
        wait 500
        jump @CloseBobCatTrunkMENU
                                     end
                                  end
                               end
                            end
                         end
                      end
                   end
                end
             end
           end
        end
     end
  end




/////////////Truck is already full of "borrowed" itens. 
if 
  $StoredItens == $MaxObjectsToSteal_Value
  then 
    0AD1: show_formatted_text_highpriority "~w~My God, how can i be this dumb? It's already full!" time 2100
 end   
wait 1500
jump @CloseBobCatTrunkMENU 


////////////////////////////////////////////////////////////--------------------------------------------------------------------------------------------------------------------------
////////////////////////////////////////////////////////////--------------------------------------------------------------------------------------------------------------------------
:WhichItensToSteal_TextBoxTESTE  //// SHOW OBJECTS TO STEAL 
wait 0 
if
 not $StoredItens >= $MaxObjectsToSteal_Value 
then
    // Display Slots 1, 2, and 3
    0AD1: show_formatted_text_highpriority "Steal: 1: %s (x%d) ~n~2: %s (x%d) ~n~3: %s (x%d)" time 2000 $ObjNam1 $ObjVal1 $ObjNam2 $ObjVal2 $ObjNam3 $ObjVal3
    wait 2000

    // Display Slots 4, 5, and 6
    0AD1: show_formatted_text_highpriority "4: %s (x%d) ~n~5: %s (x%d) ~n~6: %s (x%d)" time 2000 $ObjNam4 $ObjVal4 $ObjNam5 $ObjVal5 $ObjNam6 $ObjVal6
    wait 2000
    
        // Display Slots 7, 8 and 9 
    0AD1: show_formatted_text_highpriority "7: %s (x%d) ~n~8: %s (x%d)" time 1500 $ObjNam7 $ObjVal7 $ObjNam8 $ObjVal8 
    wait 900
end

///////////************************************************
:WhichItensToSteal_TextBox
wait 0 
if not $StoredItens >= $MaxObjectsToSteal_Value 
then
    // Group 1
    0AD1: show_formatted_text_highpriority "1: %s (x%d) ~n~2: %s (x%d) ~n~3: %s (x%d)" time 2000 $ObjNam1 $ObjVal1 $ObjNam2 $ObjVal2 $ObjNam3 $ObjVal3
    wait 1800

    // Group 2 (Separated to prevent buffer corruption on Slot 4)
    0AD1: show_formatted_text_highpriority "4: %s (x%d) ~n~5: %s (x%d) ~n~6: %s (x%d)" time 2000 $ObjNam4 $ObjVal4 $ObjNam5 $ObjVal5 $ObjNam6 $ObjVal6
    wait 1800
    
    // Group 3
    0AD1: show_formatted_text_highpriority "7: %s (x%d) ~n~8: %s (x%d)" time 1500 $ObjNam7 $ObjVal7 $ObjNam8 $ObjVal8 
    wait 1200
end
return



return
/////////////////////////////////////////////////////////////////-----------------------------------------------------------------------------------------------------------------------







01C0: $PlayerWantedL = player $PLAYER_CHAR wanted_level
///////////////////////////////////////////////////////////
:DropOffBobCat
wait 0 

gosub @MissionFailedCheck

///////////////////------------------------
if and
 00DB: actor $PLAYER_ACTOR in_car 3@ &&
 not $PlayerWantedL > 0  
 then
  if  
    00EE: actor $PLAYER_ACTOR sphere 0 near_point 1122.7758 -868.9712 radius 2.0 2.0 in_car
  then
    0164: remove_marker $DropOffBobCat
    Player.CanMove($PLAYER_CHAR) = false
    03BF: set_player $PLAYER_CHAR ignored_by_everyone 1
    015F: set_camera_position 1119.3668 -861.3921 43.3112 rotation 0.0 0.0 245.3208
    0160: set_camera_point_at 1122.7758 -868.9712 43.1797 switchstyle 2
    jump @SpawnNPCBoxville
else
  if and
    00DB: actor $PLAYER_ACTOR in_car 3@ &&
    $PlayerWantedL > 0  
  then
   print_now 'LSCP2' time 3000 flag 1 
      end
   end
end

jf @DropOffBobCat

//////////////

:SpawnNPCBoxville
wait 0 
gosub @MissionFailedCheck
///////////////////------------------------

// =====================================================
// SPAWN BOXVILLE + DRIVER
// =====================================================

// Load Boxville
0247: request_model #BOXVILLE
038B: load_requested_models

// Load actor model 28
0247: request_model #WMYCR
038B: load_requested_models

// Create Boxville
00A5: $Boxville_Cutscene = create_car #BOXVILLE at 1109.2362 -864.2469 43.2723
0175: set_car $Boxville_Cutscene Z_angle_to 277.5944

// Create NPC ID 28
009A: $BoxvilleDriver = create_actor_pedtype 4 model #WMYCR at 1101.5011 -865.7316 43.2421

// Put NPC inside driver's seat
036A: put_actor $BoxvilleDriver in_car $Boxville_Cutscene

// Release models
0249: release_model #BOXVILLE
0249: release_model #WMYCR

// =====================================================
// DRIVE TO DESTINATION
// =====================================================

05D1: AS_actor $BoxvilleDriver drive_car $Boxville_Cutscene to 1131.7144 -861.9797 43.3002 speed 15.0 0 model 0 0


////////////////////////////////////////
:BoxvilleDriving
wait 0

0407: store_coords_to  0@ 1@ 2@ from_car $Boxville_Cutscene with_offset 0.0 0.0 0.0


0509: 3@ = distance_between_XY 0@ 1@ and_XY 1131.7144 -861.9797

if
    3@ < 2.0
then
    jump @BoxvilleArrived
end

jump @BoxvilleDriving
////////////////////////////////////////////

:BoxvilleArrived
wait 0

// Stop the vehicle
04BA: set_car $Boxville_Cutscene speed_to 0.0

0221: set_player $BoxvilleDriver apply_brakes_to_car 1


// Make sure the driver stops driving
0633: AS_actor $BoxvilleDriver exit_car

if
 00DF: not actor $BoxvilleDriver driving
then
  015F: set_camera_position 1145.5083 -859.9069 47.4738 rotation 0.0 0.0 114.2567
  0160: set_camera_point_at 1122.7758 -868.9712 43.1797 switchstyle 2
  05F5: AS_actor $BoxvilleDriver goto_point_using_paths 1122.7758 -868.9712 43.1797 mode 4 time -1
end

wait 4500 

016A: fade 0 time 500
wait 500 


02EB: restore_camera_with_jumpcut
Player.CanMove($PLAYER_CHAR) = true
03BF: set_player $PLAYER_CHAR ignored_by_everyone 0

if
 $BoxvilleDriver > -1
then 
   009B: destroy_actor $BoxvilleDriver
end
if
  $Boxville_Cutscene > -1 
then
 00A6: destroy_car $Boxville_Cutscene
end  

03BD: destroy_sphere $DropOffBobCat
0164: disable_marker $DropOffBobCat_Marker

gosub @DeleteStolenObjects  ///// Delete stolen objects player migh've taken to the drop off point.
0AD1: show_formatted_text_highpriority "~g~ MISSION PASSED!" time 4500
wait 3500
$BurglaryPayout = $StoredItens
$BurglaryPayout *= 1500
0AD1: show_formatted_text_highpriority "~g~Payout:~w~ $%d" time 3000 $BurglaryPayout
0109: player $PLAYER_CHAR money += $BurglaryPayout
$ONMISSION = 0
016A: fade 1 time 500
wait 500 

///////////////////////////////////////////////////
0209: $GotInATrap = random_int_in_ranges 0 350

if 
  $GotInATrap == 203
then
   0AD1: show_formatted_text_highpriority "~r~POLICE HAVE FOUND OUT ABOUT YOU! JUST RUN AWAY!!!" time 5000
   wait 5000
   010E: set_player $PLAYER_CHAR minimum_wanted_level_to 4
   wait 760000
   jump @Restart
else
jump @MissionCleanup   
end
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
:DeleteStolenObjects
wait 0 
if
    $BobCat_Trunk1_Obj > -1
then
    0108: destroy_object $BobCat_Trunk1_Obj
end
if
    $BobCat_Trunk2_Obj > -1
then
    0108: destroy_object $BobCat_Trunk2_Obj
end
if
    $BobCat_Trunk3_Obj > -1
then
    0108: destroy_object $BobCat_Trunk3_Obj
end
if
    $BobCat_Trunk4_Obj > -1
then
    0108: destroy_object $BobCat_Trunk4_Obj
end
if
    $BobCat_Trunk5_Obj > -1
then
    0108: destroy_object $BobCat_Trunk5_Obj
end
if
    $BobCat_Trunk6_Obj > -1
then
    0108: destroy_object $BobCat_Trunk6_Obj
end
if
    $BobCat_Trunk7_Obj > -1
then
    0108: destroy_object $BobCat_Trunk7_Obj
end
if
    $BobCat_Trunk8_Obj > -1
then
    0108: destroy_object $BobCat_Trunk8_Obj
end
if
    $BobCat_Trunk9_Obj > -1
then
    0108: destroy_object $BobCat_Trunk9_Obj
end
if
    $BobCat_Trunk10_Obj > -1
then
    0108: destroy_object $BobCat_Trunk10_Obj
end
if
    $BobCat_Trunk11_Obj > -1
then
    0108: destroy_object $BobCat_Trunk11_Obj
end
if
    $BobCat_Trunk12_Obj > -1
then
    0108: destroy_object $BobCat_Trunk12_Obj
end

return
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////////////// MADE BY: ANDREW THIAGO








